Render JSON structure into soy template.

1,329 views
Skip to first unread message

Jayshanker Nair

unread,
Sep 3, 2012, 3:12:40 AM9/3/12
to closure-temp...@googlegroups.com
Can I render Complex JSON structure into soy template for my Tree Viewer widget?

Johannes Nel

unread,
Sep 3, 2012, 3:13:51 AM9/3/12
to closure-temp...@googlegroups.com
you can. 

you can render it on the server, you can render it on the client. you can decorate your components onto it after the fact. 


On Mon, Sep 3, 2012 at 8:12 AM, Jayshanker Nair <nairjay...@gmail.com> wrote:
Can I render Complex JSON structure into soy template for my Tree Viewer widget?



--
j:pn
\\no comment

Jayshanker Nair

unread,
Sep 3, 2012, 3:34:37 AM9/3/12
to closure-temp...@googlegroups.com
I have to render level n json into template.I have to create all the tags dynamically in the template only, I cant use javascript or jquery to do that stuff for me. 
 For That what I have to do?  

Johannes Nel

unread,
Sep 3, 2012, 3:37:49 AM9/3/12
to closure-temp...@googlegroups.com
level n just means recursion to me. not a problem. you write your template compile it and call it like a normal javascript (static) function. 


On Mon, Sep 3, 2012 at 8:34 AM, Jayshanker Nair <nairjay...@gmail.com> wrote:
I have to render level n json into template.I have to create all the tags dynamically in the template only, I cant use javascript or jquery to do that stuff for me. 
 For That what I have to do?  



Jayshanker Nair

unread,
Sep 3, 2012, 4:39:25 AM9/3/12
to closure-temp...@googlegroups.com
See my problem is any user can call my widget with different level of tree element which will be wrapped in a JSON object.So I need to create the structure of my mark up by traversing the json only.So that it can support any level of tree.So is it possible to write that recursive function inside closure template? because it needs complex computation.

Johannes Nel

unread,
Sep 3, 2012, 4:42:30 AM9/3/12
to closure-temp...@googlegroups.com
computation no, recursion yes. easily.

{template .TopLevel}
  {for each $node in $Nodes}




{/template}

On Mon, Sep 3, 2012 at 9:39 AM, Jayshanker Nair <nairjay...@gmail.com> wrote:
See my problem is any user can call my widget with different level of tree element which will be wrapped in a JSON object.So I need to create the structure of my mark up by traversing the json only.So that it can support any level of tree.So is it possible to write that recursive function inside closure template? because it needs complex computation.




Johannes Nel

unread,
Sep 3, 2012, 4:43:28 AM9/3/12
to closure-temp...@googlegroups.com
oops half typed, sent.


{template .TopLevel}
  {foreach $node in $Nodes}
{if ....}
    {call .TopLevel data="$node"/} 
{/if}
{/foreach

{/template}

Kai Huang

unread,
Sep 10, 2012, 4:58:52 PM9/10/12
to closure-temp...@googlegroups.com
If you want to check whether some data (say "$parent") has a child (say "child"), then do
{if $parent.child}...{/if}



On Monday, September 3, 2012 3:42:32 AM UTC-7, Sayan wrote:
@Johannes in our case we have to create <ul> and <li> structure accordingly to form the tree and we need to check break condition like JSON has child or not inside our template because in our case level is unknown and we cant create supporting mark up before rendering it to that template, so we have to do it on the fly. So do you have any idea how we can proceed?

Reply all
Reply to author
Forward
0 new messages