Dynamic Templates for your content

Let's first clarify potential confusion: There are two types of templates. The ones used for generation with the cli-tool, and the view templates. Here we want to focus on creating dynamic view templates.

learn more about neoan3-apps/template

Note: Alternative template engines

What you will find here is based on the assumption you are using the default neoan3-apps/template package (installs with neoan3). You can easily hook up any template engine as well. As a matter of fact, you can inject your complete own render logic.

Passing variables to the template



        namespace Neoan3\Components;

        use Neoan3\Core\Unicore;

        class MyComponentController extends Unicore{

            function init()

                    ->addRenderParameter('headline', fn() => 'My variable')
                    ->addRenderParameter('content', fn() => 'This is some fine text')
                    // the hook-method accepts 2-3 arguments
                    // the first argument describes the targeted part of the page
                    // (possible values are 'header', 'main' & 'footer')
                    // the second argument provides the wanted template
                    // (here the file /component/MyComponent/myComponent.view.html)
                    // the third argument accepts variables as array
                    // (usually the data will directly come from a model / database)
                    ->hook('main', 'myComponent', [
                        'renderParam' => 'We might also declare render parameters here.'




        <h1>My variable</h1>
        <p>This is some fine text</p>
        <p>We might also declare render parameters here.</p>

A step further

While the full documentation for templating can be found at GitHub, let's look into an examples of advanced usage:

        <!--   assuming pass-in is ['numbers' => ['name' => 'one', 'name' => 'two'] ]     -->
            <li n-for="numbers as number" n-if="number.name != 'one'">{{number.name}}</li>


        <!--   assuming pass-in is ['numbers' => ['name' => 'one', 'name' => 'two'] ]     -->