PROVIDING THE LATEST NEWS, EVENTS, AND POSTS

One recurring requirement when you are building custom websites is to provide the ability to autogenerate lists of pages or particular items (outside of standard navigation). For example, most corporate websites have something like Latest News, Upcoming Events, and so on. Obviously, it would be great if you didn't have to manually create those lists and standard content. If you did them manually, you would have to update the content in several places every time you added a news article or event to the site. Enter macros and document types (again). Building on previous examples in Chapter 5 and the use of Runway, Listing 9-4 outputs a listing of FAQs entered in your Runway website.

image The XSLT template in Listing 9-4 is originally based on the List Subpages by Document Type template that you can find in the Create new XSLT dialog (covered in Chapter 5).

LISTING 9-4: ListFaqs.xslt

image
<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp “&#x00A0;”> ]>
<xsl:stylesheet
    version=“1.0”
    xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”
    xmlns:msxml=“urn:schemas-microsoft-com:xslt”
    xmlns:umbraco.library=“urn:umbraco.library”
xmlns:Exslt.ExsltCommon=“urn:Exslt.ExsltCommon”
xmlns:Exslt.ExsltDatesAndTimes=“urn:Exslt.ExsltDatesAndTimes”
xmlns:Exslt.ExsltMath=“urn:Exslt.ExsltMath”
xmlns:Exslt.ExsltRegularExpressions=“urn:Exslt.ExsltRegularExpressions”
xmlns:Exslt.ExsltStrings=“urn:Exslt.ExsltStrings”
xmlns:Exslt.ExsltSets=“urn:Exslt.ExsltSets”
xmlns:umbusersguide.library=“urn:umbusersguide.library”
    exclude-result-prefixes=“msxml umbraco.library Exslt.ExsltCommon
Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions
Exslt.ExsltStrings Exslt.ExsltSets umbusersguide.library “>

    <xsl:output method=“xml” omit-xml-declaration=“yes” />

    <xsl:param name=“currentPage”/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name=“documentTypeAlias” select=“string(‘FAQ’)”/>

   <xsl:template match=“/”>
        <!-- The fun starts here -->
        <div class=“faq-list”>
            <xsl:for-each select=“$currentPage/*
              [name() = $documentTypeAlias and
              string(umbracoNaviHide) != ‘1’]”>
                <div class=“faq”>
                    <a href=“{umbraco.library:NiceUrl(@id)}”>
                        <xsl:value-of select=“@nodeName”/>
                    </a><br />
                    <span class=“label”>Q:</span>
                    <xsl:value-of select=“question”
                       disable-output-escaping=“yes”/>
                </div>
            </xsl:for-each>
        </div>
    </xsl:template>
</xsl:stylesheet>

image The document type alias variable that is defined in the beginning of Listing 9-4 is case sensitive. Make sure you check the casing of your document type alias if no content is being rendered from XSLT or other macros.

Similarly, rendering could certainly be done using Razor as your rendering engine, or .NET user control, or any of the other methods discussed in Chapter 5. Hopefully, you can see how you can apply the same concept to just about any content type that you need to output.

image For more examples on outputting autogenerated lists, visit http://our.umbraco.org and take a look at the wiki entries.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset