tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/14334-selecting-nodes-from-a-data-definitionCascade CMS: Discussion 2016-06-22T12:53:45Ztag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T15:23:53Z2016-06-17T15:23:53ZSelecting nodes from a data definition<div><p>Hi,</p>
<p>Before I try to offer help, I want one thing clarified. About
the data definition you provided, is it a data definition
associated with a content type, or is it used by data definition
blocks? it does not look like one for pages, because it is too
simple. It does not look like one for data definition blocks,
because in your Velocity code you dealt with
<code>calling-page</code>. How should I understand your data
definition?</p>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T15:31:45Z2016-06-17T15:34:55ZSelecting nodes from a data definition<div><p>As it stands now, the data definition is not associated with a
content type, but I didn't think it had to be when I am just trying
to learn. It is tied to a calling page block on a section of a page
template.</p>
<p>Eventually, I would like the macro to iterate over each
student-year group and display each student-term group with it's
containing courses. Just trying to get anything to display now.</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T15:35:39Z2016-06-17T15:37:15ZSelecting nodes from a data definition<div><p>I assume that by "on a section of a page template", you mean
that the block is attached to a region at the page level. Correct
me if I am wrong.</p>
<p>What do you mean by "It is tied to a calling page block"? Since
the calling-page block is an index block, how do you tie a data
definition with an index block?</p>
<p>There reason why I ask these questions: I want to duplicate your
setup so that I can write the Velocity format.</p>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T15:41:17Z2016-06-17T15:41:17ZSelecting nodes from a data definition<div><p>I am not tying the data definition itself to the calling page
block. I meant to say that I had a content region with a calling
block and my Velocity format on a page template that uses the Data
Definition. Does that make sense?</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T15:51:13Z2016-06-17T15:51:13ZSelecting nodes from a data definition<div><p>Let me try this. Go to Cascade. Look at the data definition, and
click the Relationships tab on the top. What do you see?</p>
<p>One more thing. On my site, you can find <a href="http://www.upstate.edu/cascade-admin/formats/velocity/course/index.php">
Velocity Tutorial</a>. You might want to try that, though the
tutorial goes very deep into Velocity.</p>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T15:59:38Z2016-06-17T15:59:38ZSelecting nodes from a data definition<div><p>It shows my content type of "Programs of Study". This has the
data definition that the page template is based off of. Am I doing
something wrong? There are so many parts to remember.</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T16:47:24Z2016-06-17T16:47:45ZSelecting nodes from a data definition<div><p>OK, try the following:<br></p>
<pre>
#set ( $page = $_XPathTool.selectSingleNode( $contentRoot, "calling-page/system-page" ) )
#set ( $data = $page.getChild( "system-data-structure" ) )
#set( $progName = $data.getChild( "program-name" ).value )
Program name: $progName<br />
#set( $progDesc = $data.getChild( "program-description" ).value )
Program Description: $progDesc<br />
#set( $courseSequ = $data.getChild( "course-sequence" ) )
#set( $year = $_XPathTool.selectSingleNode( $courseSequ, "student-year/year/value" ).value )
Year: $year<br />
#set( $studTerm = $courseSequ.getChild( "student-year" ).getChild( "student-term" ) )
#set( $term = $studTerm.getChild( "term" ).getChild( "value" ).value )
Term: $term<br />
#courseSequence( $year $studTerm ) ## not $term!!!
#macro( courseSequence $yr $trm )
<ul>
#foreach( $num in [1..5] )
#set( $courseName = $trm.getChild( "course-${num}" ).value )
#set( $courseCredit = $trm.getChild( "course-${num}-credit" ).value )
<li>$courseName: $courseCredit</li>
#end
</ul>
#end
</pre>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T18:36:05Z2016-06-17T18:36:05ZSelecting nodes from a data definition<div><p>Perfect Wing!<br>
I didn't think about using an array in the foreach either. Is that
syntax something specific to VTL? I hadn't seen it in Java or
C#.</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T18:48:22Z2016-06-17T18:49:27ZSelecting nodes from a data definition<div><p><code>[1..5]</code> is a java.util.ArrayList<E> object.
The syntax of <code>#foreach</code> is similar to Java's
counterpart <code>for( int num : nums )</code>.</p>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T19:37:06Z2016-06-17T19:37:06ZSelecting nodes from a data definition<div><p>Thanks Wing!</p>
<p>I've tried to add the functionality to list all the additional
terms in the year, but I am not quite getting it. It is pulling
only the first term and repeating it for the number of actual
"student-term" groups I have entered on my page.</p>
<pre>
<code>#set ( $page = $_XPathTool.selectSingleNode( $contentRoot, "calling-page/system-page" ) )
#set ( $data = $page.getChild( "system-data-structure" ) )
#set( $progName = $data.getChild( "program-name" ).value )
<h2>$progName Course Sequence</h2>
#set( $seqGroup = $_XPathTool.selectNodes($data, "course-sequence/student-year") )
#set( $courseSequ = $data.getChild( "course-sequence" ) )
#set( $year = $_XPathTool.selectSingleNode( $courseSequ, "student-year/year/value" ).value )
#set( $studTerm = $courseSequ.getChild( "student-year" ).getChild( "student-term" ) )
#set( $terms = $_XPathTool.selectNodes($seqGroup, "student-term") )
#set( $term = $studTerm.getChild( "term" ).getChild( "value" ).value )
Year: $year<br />
#foreach( $num in $terms)
Term: $term<br />
<div>#courseSequence( $year $studTerm )</div>
#end
#macro( courseSequence $yr $trm )
<ul>
#foreach( $num in [1..5] )
#set( $courseName = $trm.getChild( "course-${num}" ).value )
#set( $courseCredit = $trm.getChild( "course-${num}-credit" ).value )
<li>$courseName: $courseCredit</li>
#end
</ul>
#end</code>
</pre></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T20:04:20Z2016-06-17T20:07:22ZSelecting nodes from a data definition<div><p>You are not looping through the correct object:<br></p>
<pre>
#set( $page = $_XPathTool.selectSingleNode( $contentRoot, "calling-page/system-page" ) )
#set( $data = $page.getChild( "system-data-structure" ) )
#set( $progName = $data.getChild( "program-name" ).value )
<h2>$progName Course Sequence</h2>
#set( $seqence = $data.getChild( "course-sequence" ) )
#set( $studentYears = $seqence.getChildren( "student-year" ) )
#if( $studentYears.size() > 0 )
#foreach( $studentYear in $studentYears )
#set( $year = $_XPathTool.selectSingleNode( $studentYear, "year/value" ).value )
#set( $studTerm = $studentYear.getChild( "student-term" ) )
#set( $term = $_XPathTool.selectSingleNode( $studTerm, "term/value" ).value )
Year: $year<br />
Term: $term<br />
<div>#courseSequence( $year $studTerm )</div>
#end
#end
#macro( courseSequence $yr $trm )
<ul>
#foreach( $num in [1..5] )
#set( $courseName = $trm.getChild( "course-${num}" ).value )
#set( $courseCredit = $trm.getChild( "course-${num}-credit" ).value )
<li>$courseName: $courseCredit</li>
#end
</ul>
#end
</pre>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T20:40:32Z2016-06-17T20:40:32ZSelecting nodes from a data definition<div><p>For some reason, this only pulls the first term of each
year.</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-17T21:03:34Z2016-06-17T21:03:34ZSelecting nodes from a data definition<div><p>I forgot that <code>student-term</code> is also a multiple
field. Then when you retrieve the elements, use <code>getChildren(
"student-term" )</code> instead. Of course you need to loop through
the elements you retrieve. Can I leave this to you?</p>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-20T14:05:13Z2016-06-20T14:09:12ZSelecting nodes from a data definition<div><p>Wing, I've tried, but I can't seem to get more than 2 terms to
display for some reason. Currently it only iterates through the
years, of which I have created 2. So you are right, It needs to
iterate through the "student-terms" as well, I just can't get it to
happen.</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-20T14:16:54Z2016-06-20T14:20:03ZSelecting nodes from a data definition<div><p>Try this:</p>
<pre>
#set( $page = $_XPathTool.selectSingleNode( $contentRoot, "calling-page/system-page" ) )
#set( $data = $page.getChild( "system-data-structure" ) )
#set( $progName = $data.getChild( "program-name" ).value )
<h2>$progName Course Sequence</h2>
## there is only one course-sequence element
#set( $seqence = $data.getChild( "course-sequence" ) )
## the course-sequence element can have multiple student-year elements
#set( $studentYears = $seqence.getChildren( "student-year" ) )
#foreach( $studentYear in $studentYears )
#set( $year = $_XPathTool.selectSingleNode( $studentYear, "year/value" ).value )
#set( $studTerms = $studentYear.getChildren( "student-term" ) )
Year: $year<br />
#foreach( $studTerm in $studTerms )
#set( $term = $_XPathTool.selectSingleNode( $studTerm, "term/value" ).value )
Term: $term<br />
<div>#courseSequence( $year $studTerm )</div>
#end
#end
#macro( courseSequence $yr $trm )
<ul>
#foreach( $num in [1..5] )
#set( $courseName = $trm.getChild( "course-${num}" ).value )
#set( $courseCredit = $trm.getChild( "course-${num}-credit" ).value )
<li>$courseName: $courseCredit</li>
#end
</ul>
#end
</pre>
<p>I removed the size test because a multiple field must have at
least one instance.</p>
<p>Wing</p></div>Wing Ming Chantag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-20T14:32:43Z2016-06-20T14:32:43ZSelecting nodes from a data definition<div><p>Thanks for all your help Wing! It's working correctly now!</p>
<p>I believe I will have to practice writing a few more of
these.</p></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-20T20:52:11Z2016-06-20T20:52:11ZSelecting nodes from a data definition<div><p>I decided that my field "program-description" needed to be a
WYSIWYG, but none of the formatting is working when it's pulled in.
Do I need to change something in my format?</p>
<pre>
<code>#set ( $page = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page") )
#set ( $data = $page.getChild("system-data-structure") )
#set ( $progName = $data.getChild("program-name") )
#set ( $progDesc = $data.getChild("program-description") )
<h2>$_EscapeTool.xml($progName.value)</h2>
<p>$_EscapeTool.xml($progDesc.value)</p></code>
</pre></div>voltmer1tag:help-archives.hannonhill.com,2010-02-09:Comment/401373052016-06-22T12:53:44Z2016-06-22T12:53:44ZSelecting nodes from a data definition<div><p>Hi,</p>
<p>I noticed your latest comment is a duplicate of <a href="http://help.hannonhill.com/discussions/velocity-formats/14348-wysiwyg-in-data-definition-not-outputting-text-formatting-on-the-page">
this discussion</a> you opened up recently. To help avoid
confusion, I am going to go ahead and close this one out in favor
of the other.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions about your initial problem.</p>
<p>Have a great day!</p></div>Ryan Griffith