display content from block choosers allowing multiples

lauren.fraser's Avatar

lauren.fraser

27 Apr, 2016 05:44 PM

We have a block chooser that allows users to choose multiple blocks in a data definition.

I'm trying to use a #foreach loop to show the content for each block that has been chosen.

Here is some sample xml

<system-index-block current-time="1461777249390" name="content-center" type="folder">
    <calling-page>
        <system-page current="true" id="58b053b2ac105ad02f31480093f3556d">
            <name>stacy-dobbs</name>
            <title>Stacy Dobbs, FNP-BC</title>
            <display-name>Stacy Dobbs, FNP-BC</display-name>
            <path>/providers/stacy-dobbs</path>
            <site>Ellett</site>
            <link>site://Ellett/providers/stacy-dobbs</link>
            <created-by>lfraser</created-by>
            <created-on>1461776831366</created-on>
            <last-modified-by>lfraser</last-modified-by>
            <last-modified>1461777185906</last-modified>
            <system-data-structure definition-path="Provider Page">
                <image>
                    <path>/</path>
                </image>
                <mainContent>
                    <p>Stacy Dobbs was born at Golden Valley Memorial Hospital, and grew up in Missouri, but after high school decided to see more of the US and moved to the Pacific North West. Eventually she ended up in Wenatchee Washington where she attended Wentachee Valley College for an Associate Degree in Nursing.&#160; Since that time she has worked in Sports Medicine/Occupational Medicine.&#160; In 2004 Stacy moved back to Missouri, and worked at Western Missouri Medical Center on their Medical Nursing Unit.&#160; &#160;She pursued a Bachelor&#8217;s Degree in Nursing through Saint Louis University and then a Master&#8217;s in Nursing, graduating from Saint Louis University in 12/13/2013. &#160;She has always had a passion for rural health care.</p>
                    <p>Stacy is married with 3 children; 2 girls and a boy. &#160; &#160;She raises mules and mammoth jackstock with her family, as well as goats and Catahoula leopard dogs. &#160;</p>
                </mainContent>
                <location type="block">
                    <content>
                        <h4>A.C. Rural Health Clinic</h4>
                        <p>408 East 7th Street&#160;
                            <br/>Appleton City, Missouri 64724&#160;
                            <br/>Phone: (660) 476-2121&#160;
                            <br/>Fax: (660) 476-2130
                        </p>
                    </content>
                    <path>/_internal/blocks/locations/rural-health-clinic</path>
                    <site>Ellett</site>
                    <name>rural-health-clinic</name>
                </location>
                <location type="block">
                    <content>
                        <h4>Ellett Memorial Hospital</h4>
                        <p>610 North Ohio Avenue 
                            <br/> Appleton City, Missouri 64724
                        </p>
                        <p>Phone: (660) 476-2111&#160;
                            <br/>
                            <br/>
                        </p>
                    </content>
                    <path>/_internal/blocks/locations/ellett-hospital</path>
                    <site>Ellett</site>
                    <name>ellett-hospital</name>
                </location>
            </system-data-structure>
        </system-page>
    </calling-page>
</system-index-block>

And the format I am currently working on:

#set ($mainContent = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/mainContent"))
#set ($image = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/image/path").value)
#set ($locatins = $_XPathTool.selectNodes($contentRoot,"//system-block"))
##set ($locations =$_XPathTool.selectNodes($contentRoot,"/system-index-block/calling-page/system-page/system-data-structure/location/"))
<div class="split3"><img src="${image}" /></div> <div class="split23">$_SerializerTool.serialize($mainContent, true) #foreach ($location in $locations) #set ($location =$locations.getChild("locations").getChild("content")) $_SerializerTool.serialize($location, true) #end </div>
  1. 1 Posted by Ryan Griffith on 27 Apr, 2016 05:48 PM

    Ryan Griffith's Avatar

    Hi Lauren,

    It looks like you are on the right track, but need to tweak your XPath and loop slightly. When you have a moment, give the following a try and let me know how it works out:

    #set ($pageSD = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure"))
    #set ($mainContent = $_XPathTool.selectSingleNode($pageSD, "mainContent"))
    #set ($image = $_XPathTool.selectSingleNode($pageSD, "image/path").value)
    #set ($locations = $_XPathTool.selectNodes($pageSD, "location"))
    <div class="split3"><img src="${image}" /></div>
    <div class="split23">$_SerializerTool.serialize($mainContent, true)
    #if ($locations.size() > 0)
        #foreach ($location in $locations)
            $_SerializerTool.serialize($location.getChild("content"), true)
        #end
    #end
    </div>
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by lauren.fraser on 27 Apr, 2016 06:10 PM

    lauren.fraser's Avatar

    Thanks for the quick reply! The code you sent worked perfectly.

  3. 3 Posted by Ryan Griffith on 27 Apr, 2016 06:56 PM

    Ryan Griffith's Avatar

    Not a problem at all, Lauren. I am glad to hear the code I provided did the trick..

    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!

  4. Ryan Griffith closed this discussion on 27 Apr, 2016 06:56 PM.

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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM