Iterating without generating html elements

10 views
Skip to first unread message

Jeff Schnitzer

unread,
Nov 10, 2011, 9:24:09 PM11/10/11
to cambridge...@googlegroups.com
I want to generate some templated json/javascript on a page. It
requires iterating; basically I want to generate the blahs in:

var foo = [ blah, blah, blah, blah ];

Is this possible with cambridge? I can iterate and generate html
elements, but it's not obvious how to do this without adding the html.

Thanks,
Jeff

Erdinc Yilmazel

unread,
Nov 10, 2011, 10:27:06 PM11/10/11
to cambridge...@googlegroups.com
This is possible with hidden tags. Any tag can be hidden by adding a:hide attribute so you can have something like the following:

var foo = [ <span a:foreach="foo" a:as="bar" a:hide>$bar</span> ];

a:hide makes the tag itself hidden from the rendered output, so it doesn't matter if the tag is a <span>, <foo> or <bar> it will be all the same. There is also the <a:span> tag, which is a dynamic tag that is hidden by default. With <a:span> it requires less typing:

var foo = [ <a:span foreach="foo" as="bar">$bar</a:span> ];

I hope this helps.

 - Erdinc

Jeff Schnitzer

unread,
Nov 10, 2011, 10:28:10 PM11/10/11
to cambridge...@googlegroups.com
Great! That is exactly what I was hoping for.

Thanks,
Jeff

Reply all
Reply to author
Forward
0 new messages