tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/10815-simple-loop-in-velocityCascade CMS: Discussion 2014-09-12T19:55:09Ztag:help-archives.hannonhill.com,2010-02-09:Comment/343750242014-08-29T00:37:46Z2014-08-29T00:37:46ZSimple loop in velocity <div><p>Hi Matthew,</p>
<p>Looking over your Velocity, I am not seeing a loop for your
<code><document-links></code> elements. Think of Velocity as
a language like Java, PHP, or JavaScript where you obtain an array
and loop over each element.</p>
<p>When you have a moment, try the following and let me know how it
works out:</p>
<pre>
<code>#set ( $title = $_XPathTool.selectSingleNode($contentRoot, "/system-data-structure/title") )
#set ( $docLinks = $_XPathTool.selectNodes($contentRoot, "//document-links") )
<div class="body">
<h1>${_EscapeTool.xml($title.value)}</h1>
#if ($docLinks.size() > 0)
#foreach ($dl in $docLinks)
#set ( $linkTitle = $_EscapeTool.xml($dl.getChild("link-title").value) )
#set ( $link = $_EscapeTool.xml($dl.getChild("external-link").value) )
<div>
<a href="${link}"><h2>${linkTitle}</h2></a>
</div>
#end
#end
</div></code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffith