Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Available Variables

What's the best way to see variables available to a template? I have a sub-template that I'm including in various templates, but I'd like to know what the name of the calling template was.

Comments

  • Hmm, I don't think it actually keeps track of that for the included templates, but it shouldn't be hard to add. I'll take a look at the Template class in a bit. Probably just a matter of adding a special variable to keep track of that.

    To see everything sent to the template, you can include <?=info($data)?> in the template.

  • Thanks. Is this something that Boris REPL would be useful for?

  • Perhaps, but not if you need it dynamically in the template itself.

    I just pushed a commit that adds a {{parent_template_id}} to included templates. You can also use it via {% if parent_template_id %} to determine whether the template is included or called via PHP, or {% if parent_template_id == 'myapp/main-template' %} to determine where it was included.

    This also highlighted an issue that after an include, the {{template_id}} value would still be set to the included template afterwards in the main template, so I fixed that by cloning the $data object first.

Sign In or Register to comment.