Data Access in Templates

37 views
Skip to first unread message

Behrad Zari

unread,
Jul 18, 2012, 6:47:55 PM7/18/12
to zotoni...@googlegroups.com
I have a list of tuples like

    [ { "Param1", "value1" }, { "Param2", "value2"} ], ...

I found that converting first tuple keys to atoms 'Param1' is not sufficient to access them
in my template via {{props.Param1}} !!! Params are starting with upper-case characters!

What is the best practice structure that I should convert my data to, to use it simply in templates!?

Marc Worrell

unread,
Jul 18, 2012, 6:54:44 PM7/18/12
to zotoni...@googlegroups.com
That is strange, I just tried it on the command line and it works there:

(zoton...@Lamma.local)5> erlydtl:compile(<<"{{ v.Data }}">>, t, z:c(zotonic_status)).
{ok,t}
(zoton...@Lamma.local)6> t:render([{v, [{'Data',123}]}], z:c(zotonic_status)).       
{ok,["123"]}

How does your variable list look like?

- Marc

Wes James

unread,
Jul 19, 2012, 12:48:05 AM7/19/12
to zotoni...@googlegroups.com
You have ' ' around Data, he has "" around his item.  Isn't yours an atom and his a string and how does zontonic treat the difference?

wes

Arjan Scherpenisse

unread,
Jul 19, 2012, 2:41:25 AM7/19/12
to zotoni...@googlegroups.com
Yes, but Behrad says that he converts the proplist keys to atoms before
passing them to Erlydtl.
So indeed, the question for Behrad is how the variables look just before
they are handed off to Erlydtl?

Arjan

On 07/19/2012 06:48 AM, Wes James wrote:
> You have ' ' around Data, he has "" around his item. Isn't yours an
> atom and his a string and how does zontonic treat the difference?
>
> wes
>
> On Wed, Jul 18, 2012 at 4:54 PM, Marc Worrell <mwor...@me.com
> <mailto:mwor...@me.com>> wrote:
>
> That is strange, I just tried it on the command line and it works there:
>
>> (zoton...@Lamma.local <mailto:zoton...@Lamma.local>)5>
>> erlydtl:compile(<<"{{ v.Data }}">>, t, z:c(zotonic_status)).
>> {ok,t}
>> (zoton...@Lamma.local <mailto:zoton...@Lamma.local>)6>

Marc Worrell

unread,
Jul 19, 2012, 3:45:28 AM7/19/12
to zotoni...@googlegroups.com
Another option is to fetch the variable this way:

(zoton...@Lamma.local)10> erlydtl:compile(<<"{{ v['Data'] }}">>, t, z:c(zotonic_status)).
{ok,t}
(zoton...@Lamma.local)11> t:render([{v, [{"Data",123}]}], z:c(zotonic_status)).
{ok,["123"]}

Then you should be able to access your args without conversion.

- Marc

JRad

unread,
Jul 21, 2012, 9:12:36 AM7/21/12
to zotoni...@googlegroups.com
Actually I'm using mod_signal signal data, which is accessed by key 'signal_props'!
that works in shell, but not for my example which is:
This template 
<p>{{ signal_props }}</p>
outputs:
{"Event-Name","HEARTBEAT"}{"Core-UUID","ff9f6a1f-bfc3-4243-b7af-7f2877a43402"}{"Hostname","opxi2Server"}{"Switchname","opxi2Server"}{"IPv4","192.168.1.20"}

which seems to be a list printed by erlydtl but this one,
<p>{{ signal_props['Event-Name'] }}</p>
outputs nothing! (no-errors)

Why? and I also was wondering if we can samely access nested keys? a.v[‎'Data']?

JRad

unread,
Jul 21, 2012, 9:20:56 AM7/21/12
to zotoni...@googlegroups.com
Oh, It was a mistake, that list was being nested to another list where signal was emitted!
Thank you again, I am enjoying to play with erlangish Zotonic!
Reply all
Reply to author
Forward
0 new messages