Jump to content

Template Engine Latte


d'Hinnisdaël
 Share

Recommended Posts

Add support for the Latte templating language to the Template Engine Factory.

Available on the module directory and on GitHub. The latest version uses Latte v3.

 

Configuration

The module offers the usual the following configuration:

Template files suffix
The suffix of the Latte template files, defaults to latte.

Default layout file
Layout that all views will extend from unless overwritten.

Provide ProcessWire API variables in Latte templates
API variables ($pages, $input, $config...) are accessible in Latte, e.g. {$config} for the config API variable.

Simplified path resolution
Enable Blade-style dot syntax for directory traversal, e.g. 
partials.navigation instead of ../../partials/navigation.latte

Auto refresh templates (recompile)
Recompile templates whenever the source code changes.

  • Like 6
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...

@maetmar When rendering templates using Latte, I've found the built-in field rendering a bit cumbersome to set up since you'll need an intermediary PHP file to render the Latte view from.

The straight-forward version would be using a loop and including a file based on the matrix type. This will look for a view partial at site/templates/views/partials/blocks/image.latte, when rendering a matrix page of the type "image" in a matrix field named "blocks":

{foreach $page->blocks as $block}
    <div class="block" data-block="{$block->type}">
        {include 'partials.blocks.' . $block->type, block => $block}
    </div>
{/foreach}

 

Link to comment
Share on other sites

thanks, it works that way!

One more thing, I found to get this warning due to PHP 8.2:

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /usr/www/users/xxxxxxxxxx/site/modules/TemplateEngineLatte/src/TemplateEngineLatte.php on line 139

Link to comment
Share on other sites

In my templates I normaly call a _init.php file as prepend to initialize / set some variables, etc.

However, as soon as I activate "Enalobe automatic page rendering" in the "Template Engine Factory" Module, this _init.php seems to be nor longer called and therefore my default setting values are undefined and can not be used.

Any Idea how to fix this behaviour?

If I disable this feature, the system still calls my "standard.php" file including the _init.php call upfront. So maybe I could just load the latte template from within standard.php ? But I donßt know how to call it properly. 

thanks for any help

Link to comment
Share on other sites

@maetmar It's probably best to ask this in the dedicated forum topic for the TemplateEngineFactory module. The Latte engine has no influence on this behavior, it merely renders the output.

For what it's worth, I have that option enabled and my _init.php is being called normally, so it might be something else.

Link to comment
Share on other sites

@maetmar You don't need to call or render anything. That's basically what TemplateEngineFactory does for you behind the scenes. For every template.php, it will look for a corresponding view file, e.g. template.latte or template.twig. Looking at the module again, for that to happen, you need the mentioned option enabled: Enable automatic page rendering. Why this would interfer with your prepended _init.php, I don't know and is something to debug.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...