Targeting index block with XSLT

Nicole Foster's Avatar

Nicole Foster

09 Oct, 2014 08:30 PM

Hi,

I'm looking to create a "module" that will display the 5 most recent blog posts from within the site.

The blog is set up with a homepage that pulls from a folder called current-stories which has all the blog posts.

I have created a index block called news to grab all the pages within that folder. I will change it to only 5 once I get this working. The screenshot below shows the parameters for that index block.

I created a format to grab the post title and link to the blog to display within a list. Here is the format:

 <!-- recent blog posts -->
            <xsl:if test="content/system-data-structure/blog-index-block/path != '/'">   
                <div>
                    <xsl:attribute name="class">sidebarmod</xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="content/system-data-structure/title != ''">
                            <h2>
                                <xsl:value-of select="content/system-data-structure/title"/> 
                            </h2>                    
                        </xsl:when>
                    </xsl:choose>
                    <xsl:for-each select="content/system-data-structure/blog-index-block/content/system-index-block/system-page">
                        <a>
                            <xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
                            <xsl:value-of select="display-name"/>
                        </a>
                    </xsl:for-each>      
                </div>
            </xsl:if>

Here is the XML data definition to make this module to put on any page the user desires:

<system-data-structure>
  <text identifier="title" label="Title"/>
  <asset type="block" identifier="blog-index-block" label="Blog Index Block" required="true" help-text="This will located in _internal/blocks and called blog-index"/>
</system-data-structure>

Unfortunately, the block only shows the Title of the module (system-data-structure/title), but no title or link to the blog posts themselves. I believe I just don't have the right formats for it.

Could I get a second look at this?

Thank you,
Nicole Foster

  1. Support Staff 1 Posted by Tim on 09 Oct, 2014 09:02 PM

    Tim's Avatar

    Hi Nicole,

    When you have the chance, can you please attach:

    • The Index Block XML
    • Your entire XSLT Format

    Thanks!

  2. 2 Posted by Nicole Foster on 10 Oct, 2014 12:57 PM

    Nicole Foster's Avatar

    Here is the index block XML (Sorry it's disorganized):

    
    <?xml version="1.0" encoding="UTF-8"?>
    <system-index-block name="news" type="folder" current-time="1412945530741"><system-page id="a78e3aef80e612702e98f8644c5abd83"><name>ahern-gift</name><is-published>true</is-published><last-published-on>1412697893591</last-published-on><last-published-by>nafoster</last-published-by><display-name>Special Initiatives Fund</display-name><path>/blog/current-stories/ahern-gift</path><site>DSA-Master-New</site><link>site://DSA-Master-New/blog/current-stories/ahern-gift</link><created-by>nafoster</created-by><created-on>1407265422023</created-on><last-modified-by>nafoster</last-modified-by><last-modified>1411754604716</last-modified><system-data-structure definition-path="news"><banner><banneritem><bannertitle /><bannerimage><content /><path>/_images/blog/generic_sub_feature_news3.jpg</path><link>site://DSA-Master-New/_images/blog/generic_sub_feature_news3.jpg</link><site>DSA-Master-New</site><name>generic_sub_feature_news3.jpg</name><display-name>generic_sub_feature_news3</display-name><title>generic_sub_feature_news3</title></bannerimage></banneritem></banner><newspreview><newsimage><content /><path>/_images/blog/pro_ahern_gift.jpg</path><link>site://DSA-Master-New/_images/blog/pro_ahern_gift.jpg</link><site>DSA-Master-New</site><name>pro_ahern_gift.jpg</name><display-name>pro_ahern_gift</display-name><title>pro_ahern_gift</title></newsimage><newsdate>May 15, 2014</newsdate><preview><p>A gift from School of Architecture graduate Patrick Ahearn &amp;#8217;73 will create the Ahearn Special Initiatives Fund, supporting key activities and events to raise the school&amp;#8217;s profile nationally and worldwide.<a href="site://DSA-Master-New/blog/current-stories/ahern-gift"><strong><br />
    </strong></a></p></preview><link><link>http://</link><page><content /><path>/blog/current-stories/ahern-gift</path><link>site://DSA-Master-New/blog/current-stories/ahern-gift</link><site>DSA-Master-New</site><name>ahern-gift</name><display-name>Special Initiatives Fund</display-name><title>Alumnus creates special initiatives fund at School of Architecture</title></page></link></newspreview><page><pagetitle>Alumnus creates special initiatives fund at School of Architecture</pagetitle><subtitle /><pagecontent><p><img alt="Patrick Ahern" height="152" src="site://DSA-Master-New/_images/blog/pro_ahern_gift.jpg" style="float: left; margin-right: 15px;" width="185" /><strong>Patrick Ahearn &amp;#8217;73,</strong> a graduate of the <strong>Syracuse University School of Architecture</strong> and member of the school&amp;#8217;s advisory board, recently made a gift to create the Ahearn Special Initiatives Fund. The fund will support key activities in critical areas and assist Dean Michael Speaks in developing special projects and events to help raise the profile of the school nationally and worldwide.</p>
    <p>&amp;#8220;We are extremely grateful to Patrick, one of our most supportive alumni and donors,&amp;#8221; Speaks says. &amp;#8220;His generous gift helps to ensure that resources are available to our students and faculty as we maintain and expand our state-of-the-art facilities, as well as new and innovative programming at the school.&amp;#8221;</p>
    <p>This past fall, Ahearn was named the Dean&amp;#8217;s Outstanding Alumnus, an award given by the School of Architecture annually to a graduate who has exhibited dedication to the school while practicing at the highest levels of the architecture discipline. Previously, Ahearn established the Patrick J. Ahearn Scholarship Endowed Fund at the School of Architecture, awarded each year to an architecture student with preference given to those from Levittown, New York, or Boston, Massachusetts. Ahearn also serves on the Boston Regional Council, which is made up of Syracuse University alumni and parents dedicated to raising the University&amp;#8217;s profile within the region.</p>
    <p>Ahearn is the founding principal of Patrick Ahearn Architect. His firm specializes in historically motivated architecture and interior design. Over the past 38 years, he&amp;#8217;s designed and built residential projects distinguished by finely crafted and detailed work, spanning classic styles of architecture from City Town Houses to Island Homes. Ahearn was inducted into the New England Design Hall of Fame in November 2013.</p></pagecontent></page><sidebar><sidebaritem><path>/</path></sidebaritem><sidebaritem><path>/</path></sidebaritem></sidebar></system-data-structure></system-page><system-page id="b23bcaa080e612701bb5139eadb99008"><name>test</name><is-published>true</is-published><last-published-on>1412697893591</last-published-on><last-published-by>nafoster</last-published-by><display-name>This is a test</display-name><path>/blog/current-stories/test</path><site>DSA-Master-New</site><link>site://DSA-Master-New/blog/current-stories/test</link><created-by>nafoster</created-by><created-on>1411739535986</created-on><last-modified-by>nafoster</last-modified-by><last-modified>1411750052483</last-modified><system-data-structure definition-path="news"><banner><banneritem><bannertitle /><bannerimage><content /><path>/_images/blog/generic_sub_feature_news3.jpg</path><link>site://DSA-Master-New/_images/blog/generic_sub_feature_news3.jpg</link><site>DSA-Master-New</site><name>generic_sub_feature_news3.jpg</name><display-name>generic_sub_feature_news3</display-name><title>generic_sub_feature_news3</title></bannerimage></banneritem></banner><newspreview><newsimage><content /><path>/_images/blog/pro_ahern_gift.jpg</path><link>site://DSA-Master-New/_images/blog/pro_ahern_gift.jpg</link><site>DSA-Master-New</site><name>pro_ahern_gift.jpg</name><display-name>pro_ahern_gift</display-name><title>pro_ahern_gift</title></newsimage><newsdate>September 26, 2014</newsdate><preview><p>This is just a test. <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur et velit molestie, pharetra ex nec, lobortis lacus.</span><a href="site://DSA-Master-New/blog/current-stories/test"><strong><br />
    </strong></a></p></preview><link><link>http://</link><page><content /><path>/blog/current-stories/test</path><link>site://DSA-Master-New/blog/current-stories/test</link><site>DSA-Master-New</site><name>test</name><display-name>This is a test</display-name><title>This is just a test</title></page></link></newspreview><page><pagetitle>This is just a test</pagetitle><subtitle /><pagecontent><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis egestas orci at rhoncus. Praesent consequat id est eget lacinia. Proin id mauris at justo cursus accumsan feugiat quis eros. Phasellus vitae porta sem. Nulla posuere efficitur est, ac bibendum mauris eleifend a. Donec ullamcorper, est sit amet scelerisque rhoncus, lectus ante hendrerit ligula, vel condimentum nibh lorem condimentum leo. Vivamus euismod ante id urna euismod, eget venenatis quam condimentum. Integer velit turpis, suscipit posuere molestie sed, ultrices quis massa. Sed nulla tortor, placerat vitae magna nec, iaculis fringilla turpis. Aliquam lobortis, urna id porttitor volutpat, velit lectus sodales quam, vel sodales enim ex ut velit. Aliquam quis odio augue. Ut sed erat ac lectus blandit sollicitudin in in tellus.</p>
    <p>Aliquam vehicula sem eget feugiat imperdiet. In hac habitasse platea dictumst. Donec in ipsum posuere, congue justo eu, volutpat urna. Phasellus convallis, leo sagittis tincidunt pretium, eros nisl interdum neque, at gravida arcu ipsum id nisi. Nulla elit orci, sollicitudin eget pulvinar in, aliquet vel nulla. Vestibulum id est risus. Sed finibus orci in ullamcorper finibus. Donec at porttitor risus. Donec viverra, nunc in mattis semper, felis urna faucibus magna, et efficitur felis nulla ac nulla.</p></pagecontent></page><sidebar><sidebaritem><path>/</path></sidebaritem><sidebaritem><path>/</path></sidebaritem></sidebar></system-data-structure></system-page></system-index-block>
    

    Here is the entire XSLT Format:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:include href="site://DSA-Master-New/_internal/stylesheets/date"/>
      <xsl:include href="site://DSA-Master-New/_internal/stylesheets/format-date"/>
        <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
        <xsl:template match="system-folder"/>
        <xsl:template match="calling-page">
            <xsl:apply-templates select="system-page"/>
        </xsl:template>
        
        <xsl:template match="system-page">        
                <xsl:apply-templates select="system-data-structure"/>
        </xsl:template>
        
        <xsl:template match="system-data-structure">
           
                        <xsl:apply-templates select="sidebar"/>
            
        </xsl:template>
    
        <xsl:template match="sidebar">
            <xsl:apply-templates select="sidebaritem"/>
        </xsl:template>
    
        <xsl:template match="sidebaritem">
            <div>
                <xsl:attribute name="id">module</xsl:attribute>
    <!-- recent blog posts -->
                <xsl:if test="content/system-data-structure/blog-index-block/path != '/'">   
                    <div>
                        <xsl:attribute name="class">sidebarmod</xsl:attribute>
                        <xsl:choose>
                            <xsl:when test="content/system-data-structure/title != ''">
                                <h2>
                                    <xsl:value-of select="content/system-data-structure/title"/> 
                                </h2>                    
                            </xsl:when>
                        </xsl:choose>
                        <xsl:for-each select="content/system-data-structure/blog-index-block/content/system-index-block/system-page">
                            <a>
                                <xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
                                <xsl:value-of select="display-name"/>
                            </a>
                        </xsl:for-each>
                        
                         
                    </div>
                </xsl:if>
    
     </div>    
        <br/>
        </xsl:template>
    
    
        <xsl:template match="page">
            
            
                <xsl:choose>
                    <xsl:when test="pagetitle != ''">
                        
                        <h2><xsl:value-of select="pagetitle"/></h2>
                    
                    </xsl:when>
                    
                </xsl:choose>
            
                <xsl:choose>
                    <xsl:when test="subtitle != ''">
                        <h3><xsl:value-of select="subtitle"/></h3>
                    </xsl:when>
                </xsl:choose>
                
                <div class="contentsection">
                <xsl:copy-of select="pagecontent/node()"/>
                </div>
            
        </xsl:template>
            
        
    </xsl:stylesheet>
    
  3. 3 Posted by Ryan Griffith on 10 Oct, 2014 01:48 PM

    Ryan Griffith's Avatar

    Hi Nicole,

    I suspect the issue may be due to your Block chooser not including the Index Block content, only it's system information. When you have a moment, edit your Data Definition, edit the blog-index-block field and set the Render Content Depth option to 4. Your block chooser should now include the content of the chosen Index Block.

    Please let us know if you have any questions.

    Thanks!

  4. 4 Posted by Nicole Foster on 10 Oct, 2014 02:05 PM

    Nicole Foster's Avatar

    Hi Ryan,

    Thank you for your help.

    That worked perfectly.

    Thanks,
    Nicole

  5. 5 Posted by Ryan Griffith on 10 Oct, 2014 02:15 PM

    Ryan Griffith's Avatar

    Not a problem at all, Nicole. I am glad to hear that did the trick.

    Have a great day!

  6. Ryan Griffith closed this discussion on 10 Oct, 2014 02:15 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