Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: How do you loop through child pages of a parent page and display meta field values?

$
0
0
Hi Bron and welcome to our forum,

first of, if you are not a huge fan of XSLT you can build this using a ASP.NET User Control or ASP.NET Razor - nice options if you are more of a C# guy.

Solving this with XSLT may be easier if you get your data (xml) served just right, so let me start by breaking this into two bits and focus on the data part first. Based on your description I duplicated your setup and made a simple XSLT function which will output the following mix of sitemap and portfolio data in one:
<PortfolioPages>
    <Page Title="Portfolio 1" URL="/Portfolio/Portfolio-1/c1mode(unpublished)" Depth="3" Thumbnail="MediaArchive:e43b0a0b-8194-407d-83ea-68deed8f9647" ExternalLink="#link1" BannerImage="MediaArchive:e43b0a0b-8194-407d-83ea-68deed8f9647"/>
    <Page Title="Portfolio 2" URL="/Portfolio/Portfolio-2/c1mode(unpublished)" Depth="3" Thumbnail="MediaArchive:6fb4c70b-12a6-4522-add6-1f40828c5452" ExternalLink="#link2" BannerImage="MediaArchive:6fb4c70b-12a6-4522-add6-1f40828c5452"/>
    <Page Title="Portfolio 3" URL="/Portfolio/Portfolio-3/c1mode(unpublished)" Depth="3" Thumbnail="MediaArchive:da01dd11-cf5a-4c68-8cb3-803918b93aeb" ExternalLink="#link3" BannerImage="MediaArchive:da01dd11-cf5a-4c68-8cb3-803918b93aeb"/>
</PortfolioPages>
So this would be your input for your "rendering xslt function" - much simpler to iterate through.

To create a function that give you this result, do the following:
  1. Make a brand new XSLT function with output type XML - give it an awesome name of your choosing (like Custom.PortfolioDetail.GetChildPageDetails)
  2. On the Settings tab, change the "Debug, Page" to your portfolio parent page - this makes your 'preview' use that page - great for debugging
  3. On the 'Function calls' tab, click the wee 'Source' button to switch to source view, paste the function code below in here and switch back to visual
  4. On the 'template' tab, paste in the XSLT shown below
  5. Preview and you should hopefully see XML similar to the above sample
At this point you can go back to your orifinal XSLT, remove the two function calls to SitemapXml and GetPortfolioDetailsXml and add a call to Custom.PortfolioDetail.GetChildPageDetails (or what you called it) instead.

With this simplified and combined XML it should be easier to create the XSLT that list it. Feel free to ask from that point.

A few notes on the stuff I did:
  • You can always call one XSLT Function from another and this can be a great way to segment things (like in any other programming language)
  • The calls to SitemapXml and GetPortfolioDetailsXml are using "page scoping" to only return child pages and only relative to 'active page'
  • If you need to go ninja on this, you can override 'active page' through the use of parameters - handy if you would want this function on the homepage also etc.
Hope this helps, otherwise keep posting.


Marcus
@CompositeC1


Function call markup
<f:functions xmlns:f="http://www.composite.net/ns/function/1.0">
    <f:function name="Custom.PortfolioDetails.GetPortfolioDetailsXml" localname="GetPortfolioDetailsXml">
        <f:param name="Filter">
            <f:function name="Custom.PortfolioDetails.ActivePageReferenceFilter">
                <f:param name="SitemapScope" value="Children" />
            </f:function>
        </f:param>
        <f:param name="PropertyNames">
            <f:paramelement value="PageId" />
            <f:paramelement value="ExternalLink" />
            <f:paramelement value="BannerImage" />
            <f:paramelement value="Thumbnail" />
        </f:param>
    </f:function>
    <f:function name="Composite.Pages.SitemapXml" localname="SitemapXml">
        <f:param name="SitemapScope" value="Children" />
    </f:function>
</f:functions>
XSLT Template
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" exclude-result-prefixes="xsl in">
    <xsl:template match="/">
        <PortfolioPages>
            <xsl:for-each select="/in:inputs/in:result[@name='SitemapXml']/Page">
                <xsl:variable name="portfolio" select="/in:inputs/in:result[@name='GetPortfolioDetailsXml']/PortfolioDetails[@PageId=current()/@Id]" />
                <Page Title="{@Title}" 
                    URL="{@URL}" 
                    Depth="{@Depth}" 
                    Thumbnail="{$portfolio/@Thumbnail}" 
                    ExternalLink="{$portfolio/@ExternalLink}" 
                BannerImage="{$portfolio/@BannerImage}"  />
            </xsl:for-each>
        </PortfolioPages>
    </xsl:template>
</xsl:stylesheet>

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>