Looping parent element not showing
I can't figure out how to loop the section. Each has a section that has a title that is also not looping. How can I make each loop and include respectively for each? Basically how the XML is structured, it's how I want the output to be as well. Hope that makes sense?
XML: Below is the short version
<?xml version="1.0" encoding="UTF-8"?>
<system-data-structure>
<main-set>
<plain-content>
<h3>Main Set One</h3>
</plain-content>
<set>...</set>
</main-set>
<main-set>
<plain-content>
<h3>Main Set Two</h3>
</plain-content>
<set>...</set>
</main-set>
<main-set>
<plain-content>
<h3>Main Set Three</h3>
</plain-content>
<set>...</set>
</main-set>
</system-data-structure>
Velocity: Full
#set($main_set = $_XPathTool.selectNodes($contentRoot, "//main-set"))
#set($wysiwyg = $_XPathTool.selectNodes($contentRoot, "//plain-content"))
#set($accordions = $_XPathTool.selectNodes($contentRoot, "//set"))
#if ($main_set.size() > 0)
#set($plain_content = $_XPathTool.selectSingleNode($wysiwyg, "//plain-content"))
## HTML output.
<div class="main-set">
${_SerializerTool.serialize($plain_content, true)}
<ul id="faqs">
#if ($accordions.size() > 0)
#foreach($accordion in $accordions)
#set($section_title = $_XPathTool.selectSingleNode($accordion, "section-title").value)
#set($content = $_XPathTool.selectSingleNode($accordion, "content"))
## HTML output.
<li class="faq-set">
<p class="question">${_EscapeTool.xml($section_title)}</p>
<div class="answer">${_SerializerTool.serialize($content, true)}</div>
</li>
#end
#end
</ul>
</div>
#else
## Don't display $plain_content
#end
- main-set.xml 8.25 KB
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 29 Jan, 2016 02:54 PM
Hi,
It looks like you're going to want to tweak this a bit. Specifically, you want to loop over each
main-set
and output the title and accordion within them, not loop over things individually.Here is a sample Format to help get you started:
Please let me know if you have any questions.
Thanks!
2 Posted by Wing Ming Chan on 29 Jan, 2016 03:06 PM
Hi,
I don't how how the ul's and li's are supposed to be nested. But I've come up with this, after cleaning up the code a bit:
Wing
3 Posted by zepedac on 01 Feb, 2016 09:38 PM
I'm working on these two suggestions. I'll update y'all with my results.
4 Posted by Ryan Griffith on 01 Feb, 2016 09:56 PM
Thank you for following up. Please keep us posted on your progress.
Have a great day!
Ryan Griffith closed this discussion on 11 Feb, 2016 01:38 PM.
zepedac re-opened this discussion on 06 Mar, 2016 04:22 AM
5 Posted by zepedac on 06 Mar, 2016 04:22 AM
I finally figured it out. A few things. Syntax misspelling with $main_sets, $wysiwygs and also creating a counter to increment by one for the faqs id. I also removed the forward slashes when setting the nodes for <main-set />, <plain-content />, and <set />. This is improving upon the code that Ryan provided.
6 Posted by Ryan Griffith on 07 Mar, 2016 01:20 PM
Thank you for following up. I am glad to hear you were able to use our sample code to develop a working solution.
I wanted to mention that each loop is given a
$foreach
context variable which has anindex
property that accomplishes this for you. You simply use$foreach.index
.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.
Have a great day!
Ryan Griffith closed this discussion on 07 Mar, 2016 01:20 PM.