• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

freemarker templating

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a hierarchical list of research items that i use a recursive function to build the list and then return this to a .htm page.

i then use a freemarker macro to display the list using
    and
  • tags.

    The problem is at the moment the code that displays the list has hard coded #assign statements for each level but i want the code to work regardless of the number of levels in the list.

    Is there a way i can dynamically create variables depending on the number of levels? e.g.



    where the variable names are 'count1', 'count2', 'count3', etc.

    Hope this makes sense?

    Liam
    [originally posted on jforum.net by liam]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HHHm... never tried this. I suggest looking at the manual of freemarker, at http://freemarker.sf.net

If you find anything, let us know

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be try this code. Or see the interpret built-ins in Freemarker manual.


[originally posted on jforum.net by wing]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this i will give it a try.
[originally posted on jforum.net by liam]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the code:

<#assign ResetCountTemplateSource="<#assign count${a} = 0 />" >
<#assign ResetCountTemplate=ResetCountTemplateSource?interpret >
<#list 0..depthOfList as a>
<@ResetCount />
</#list>



but couldn't get it to work so i tried the example on the freemarker documentation

<#assign x=["a", "b", "c"]>
<#assign templateSource = "<#list x as y>${y}</#list>">
<#assign inlineTemplate = templateSource?interpret>
<@inlineTemplate>def</@inlineTemplate>



http://freemarker.sourceforge.net/docs/ref_builtins_expert.html

And this doesn't work either, it says y is undefined.

Any ideas? I appreciate your help.

Liam
[originally posted on jforum.net by liam]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello liam,

I am very sorry. The code I post before is wrong.

Please try the following one.

[originally posted on jforum.net by wing]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That seems to work, thanks.

Liam
[originally posted on jforum.net by liam]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome
[originally posted on jforum.net by wing]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a new problem.

I have a hierarchical list and i want to disable all children of a branch.



e.g. i want to disable fruit and all children of fruit.

Is there a way I can add ids to an array or list and then check if they exist to determine whether or not to display an item?

Liam
[originally posted on jforum.net by liam]
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic