h2o-php icon indicating copy to clipboard operation
h2o-php copied to clipboard

Can $context be acessible in Template?

Open macedd opened this issue 10 years ago • 5 comments

A use case needs to have the whole context in a variable. Is it possible currently?

{{ context.length }}
{% for k,v in context %}

macedd avatar Aug 01 '14 15:08 macedd

Interesting idea, I don't think the context object should be exposure inside the context object. (If that makes any sense)

May be expose some of meta data that describe the context object. Ex. Length, stack...

Can you explain further what is the actual use cases?

Sent from my iPhone

On 2 Aug 2014, at 1:22 am, Thiago Fernandes [email protected] wrote:

A use case needs to have the whole context in a variable. Is it possible currently?

{{ context.length }} — Reply to this email directly or view it on GitHub.

speedmax avatar Aug 01 '14 22:08 speedmax

Actually cant find exactly how it would be usefull.. sorry. I ended implementing the template in another way.

In the time what looked feasible was to pass a context variable which had the other ones, by ref.

Your idea of Length and Stack would solve (on my mindset) if Context Resolver could handle dynamic variable names, like {% for var in context.stack %} {{ :var }} {% endfor %}

macedd avatar Aug 04 '14 15:08 macedd

Example 1: To encode the context (a query) into json

  • so easily pass data to the next page
  • make javascript decisions uppon the context
  • no need to print each field and control their additions

macedd avatar Sep 19 '14 12:09 macedd

Example 2: to render a sub-template with the same context

{% render 'app/table.html', context %}

macedd avatar Oct 14 '14 18:10 macedd

You can checkout the include tag that uses the current context.

On 15 Oct 2014, at 5:52 am, Thiago Fernandes [email protected] wrote:

Example 2: to render a sub-template with the same context

{% render 'app/table.html', context %} — Reply to this email directly or view it on GitHub.

speedmax avatar Oct 22 '14 05:10 speedmax