doc: Document the implicit variables which are always available in a template #541

Closed
arjan opened this Issue Mar 16, 2013 · 7 comments

Projects

None yet

4 participants

@arjan
Member
arjan commented Mar 16, 2013

For instance:

  • q
  • now
  • zotonic_dispatch

etc

cc @ArthurClemens

@arjan arjan was assigned Mar 16, 2013
@ArthurClemens
Contributor

It would be useful to mention it also here: http://zotonic.com/docs/latest/ref/tags/tag_url.html

@kaos
Member
kaos commented Jun 28, 2013

What it is actually, is that all properties of the context is available to the template.
And this is a crucial piece of information, as q, zotonic_dispatch, ... etc are not treated specially (well, now is, but not the others).

So you could have some module set a value in the context, then when a template is rendered using that context, that value would be available to it.

This may prove mighty handy! :)

@kaos
Member
kaos commented Jun 28, 2013

Ah, not entirely true any more (I was looking at a really old version of erlydtl_runtime).. there is a case for looking up properties in the context from the template, but I'm not yet sure how to do it..

@mworrell
Member

Maybe via the m.req or a new m.context model?

Often these args are added by the controller, but I see the point of making them available via a model.

@kaos
Member
kaos commented Jun 28, 2013

Yeah, a m.context sounds fine.

I'll have to take back that q wasn't treated specially.. it turns out it is.
But what of this then (from erlydtl_runtime)?

%% Other cases: context or dict module lookup.
find_value(Key, Tuple, _Context) when is_tuple(Tuple) ->
    Module = element(1, Tuple),
    case Module of
        context -> 
            z_context:get_value(Key, Tuple);
        dict -> 
            case dict:find(Key, Tuple) of
                {ok, Val} -> Val;
                _ -> undefined
            end;
        _ ->
            undefined
    end;

How do we get to this case?
(trying to figure that one out)
Since, if we can get there, then we can get props from the context without a model... :p

@mworrell
Member

You can only get there if some function returned a #context or if it was passed by a controller.
I don't know of any #context generating filters etc.

@kaos
Member
kaos commented Jun 28, 2013

Hmm.. ok.
I'm not going to touch this in the existing code in src/erlydtl/, but will look at it for src/ztl/ ( kaos/zotonic/erlydtl ).

@arjan arjan closed this in 7db2e70 Apr 17, 2014
@mworrell mworrell added a commit that referenced this issue Apr 17, 2014
@mworrell mworrell docs: some more magic query args.
Issue #541
f2b1b8e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment