Search code examples
phpsymfonymustache

Symfony2 Service reference from mustache


i have a mustache template that has the following line

{{{widgets.service_name.js.footer}}}

i found the corresponding service defined in a symfony2 bundle

service_name:
        class: A\B\C\D\EventListener\AssetsListener
        arguments:
            - @templating
            - %a.b.timestamp%
            - %kernel.environment%
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: injectAsset, priority: -255}

Is there a mustache specific meaning in .js.footer (prefix to the symfony2 service name) i am unable to find any reference related to this.

Anyone could provide some pointers i would greatly appreciate it.

Thanks


Solution

  • Dots in mustache tags are equivalent to either array access, properties or method calls. So this:

    {{{widgets.service_name.js.footer}}}
    

    Means something like this:

    $widgets['service_name']['js']['footer'];
    $widgets['service_name']->js->footer;
    $widgets['service_name']->js()->footer();
    

    … or some combination of the above. Which it actually translates to depends on what the service is, what public methods or properties it exposes, and what they return.

    Here's more on Mustache dot notation, and on variable resolution in Mustache.php.