php - Inherit dynamic template in Phalcon Volt -


i need load page, "inserted" in template - read it, volt's template inheritance should trick , does... kinda. hardcoded values, shown in examples, work fine - following example works:

<!-- template --> <div id="site_content">      {% block test %} {% endblock %} </div> 

and page, inherits template:

{% extends "../../templates/de/index.volt" %}  {% block test %}     {{ content() }} {# registered volt function outputs generated content #} {% endblock %} 

however, same page might need inherit different template , must decided on runtime, name of template must generated dynamically. 2 options occurred me:

  • set template name variable , use when extending - problem here don't see way use afterwards. that guy seems have had same problem, there neither answer of how it, nor confirmation isn't possible @ all.
  • register function generate complete string (e.g. {% extends "../../templates/de/index.volt" %}) , compile it, e.g.

    $compiler->addfunction('get_template', function ($resolvedargs, $exprargs) use ($volt) { return $volt->getcompiler() ->compilestring('{% extends "../../templates/de/index.volt" %}'); });

and use function in page, e.g.

{{ get_template() }}  {% block test %}     {{ content() }} {% endblock %} 

however, using approach not parse page content (e.g. content returned registered content() function not shown). i'm open other solutions (using twig instead of volt last resort, performance issues), advices of i'm doing wrong or pointers of useful articles on topic. in advance!

try using partials documented in phalcon doc: using partials


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -