d'Hinnisdaël Posted September 4 Share Posted September 4 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. 6 Link to comment Share on other sites More sharing options...
artfulrobot Posted October 3 Share Posted October 3 Hi @d'Hinnisdaël This looks interesting, thanks for posting. By the way, both the Getting Started link (to an #anchor) and the Documentation link (404: https://raw.githubusercontent.com/wanze/TemplateEngineFactory/v1.1.3/DOCUMENTATION.md) are broken at https://processwire.com/modules/template-engine-factory/ Link to comment Share on other sites More sharing options...
d'Hinnisdaël Posted October 3 Author Share Posted October 3 @artfulrobot Great catch. Could you repost this in the support thread of the main TemplateEngineFactory module? I have no control over either that module or its repository; I merely created an integration for it adding support for the Latte language. Link to comment Share on other sites More sharing options...
artfulrobot Posted October 3 Share Posted October 3 @d'Hinnisdaël done, sorry for barking up the wrong tree! Link to comment Share on other sites More sharing options...
maetmar Posted October 16 Share Posted October 16 Does someone have a working example of using LATTE to parse through a Repeater Matrix (pro fields)? Similar like here: https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/ just using LATTE files instead of PHP Link to comment Share on other sites More sharing options...
d'Hinnisdaël Posted October 16 Author Share Posted October 16 @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 More sharing options...
maetmar Posted October 16 Share Posted October 16 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 More sharing options...
d'Hinnisdaël Posted October 16 Author Share Posted October 16 Thanks for reporting the issue; I've pushed a fix as 1.0.6. Updating the composer package should fix it: composer update daun/template-engine-latte 1 Link to comment Share on other sites More sharing options...
d'Hinnisdaël Posted November 20 Author Share Posted November 20 I've upgraded the module to work with Latte v3. Note that this is a potential breaking change if you're defining custom macros and might require code changes on your end. Learn more about the migration to Latte 3 and upgrading macros to tags. To upgrade: composer require daun/template-engine-latte:^2.0 1 Link to comment Share on other sites More sharing options...
cwsoft Posted November 21 Share Posted November 21 @d'HinnisdaëlThanks for keeping the module updated. Latte rocks. 1 Link to comment Share on other sites More sharing options...
maetmar Posted November 22 Share Posted November 22 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 More sharing options...
d'Hinnisdaël Posted November 22 Author Share Posted November 22 @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 More sharing options...
maetmar Posted November 22 Share Posted November 22 will do so. but could you give me a working example of how to call and render standard.latte from within standard.php? would be great Link to comment Share on other sites More sharing options...
d'Hinnisdaël Posted November 22 Author Share Posted November 22 @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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now