bnomei / kirby3-handlebars

Kirby 3 Component for semantic templates with Handlebars and Mustache
MIT License
10 stars 1 forks source link

Custom variables in partials #17

Closed dorb4n closed 3 years ago

dorb4n commented 3 years ago

Hi.

Is it possible to pass custom variables to a partial, like:

{{> @link url=navigation_url class=navigation_class}}

link and class is in the link partial. When i try this, i get following error:

Bnomei\LncFiles::precompiledTemplate(): Return value must be of type string, bool returned

navigation_class and navigation_url are strings.

bnomei commented 3 years ago

you need to enable that feature in the compile flags. https://github.com/bnomei/kirby3-handlebars/wiki/Handlebars:-Templates#settings

https://github.com/zordius/lightncandy#detail-feature-list

{{>file foo bar=another}} : partial with new context which mixed with followed key value (require FLAG_RUNTIMEPARTIAL)

see defaults: https://github.com/bnomei/kirby3-handlebars/blob/f1f45f627392a6d86792efc728652f21612bd9e5/index.php#L8

site/config/config.php


<?php 

return [
     'bnomei.handlebars.compile-flags' => function () {
            // https://zordius.github.io/HandlebarsCookbook/9900-lc-options.html
            return \LightnCandy\LightnCandy::FLAG_ELSE
                | \LightnCandy\LightnCandy::FLAG_NOESCAPE
                // | \LightnCandy\LightnCandy::FLAG_PARENT
                | \LightnCandy\LightnCandy::FLAG_RUNTIMEPARTIAL // <-- uncommented from defaults
                // | \LightnCandy\LightnCandy::FLAG_NAMEDARG
                ;
        },
      // other options
];
dorb4n commented 3 years ago

Thank you :+1: Works great.