Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • tesuji 95 posts 139 karma points
    Mar 10, 2010 @ 12:32
    tesuji
    0

    List entire page content of news items

    My site has a What's New section, where I want to show the most recent news items. The news item pages are very short. I want to create a list that shows the entire content for each item (page H1, body paragraphs including anchor links) not just its node name. 

    What's the best approach - XSLT or .NET user control? Any tips on how to implement this would be greatly appreciated.

  • Max Edwards 26 posts 50 karma points
    Mar 10, 2010 @ 13:09
    Max Edwards
    0

    You should work in whatever you are most comfortable in.

    Personally I think what you are trying to do is perfect for XSLT

    <?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" 
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    <xsl:output method="xml" omit-xml-declaration="yes" />
    
    <xsl:param name="currentPage"/>
    
    <!-- Input the documenttype you want here -->
    <xsl:variable name="documentTypeAlias" select="string('NewsItem')"/>
    
    <xsl:template match="/">
    
    <!-- The fun starts here -->
    
    <xsl:for-each select="$currentPage/node [(@nodeTypeAlias = $documentTypeAlias) and (string(data [@alias='umbracoNaviHide'])) != '1']">
        <xsl:sort select="@createDate" order="descending"/>
    
        <div>
            <h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="data [@alias = 'heading']"/></a></h2>
            posted by <xsl:value-of select="@writerName"/> on <xsl:value-of select="umbraco.library:LongDate(@createDate)"/>
            <p><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="umbraco.library:StripHtml(data [@alias = 'bodyText'])" disable-output-escaping="yes"/></a></p>
        </div>
    
    
    </xsl:for-each>
    
    </xsl:template>
    
    </xsl:stylesheet>

     

    Remember to change the variable to the alias of your document type for new items.

    Also you may want to do this as a unordered list rather than each item in a div. Hopefully this should get you started though.

     

    Max

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 10, 2010 @ 13:11
    Nik Wahlberg
    0

    Hi,

    your best bet here is XSLT for sure. Just as if you were creating a navigation macro (or something like that), where you loop over nodes and out put things such as:

    <xsl:template match="/">
        <xsl:for-each select="$currentPage/node">
          <h1>
            <xsl:value-of select="current()/@nodeName"/>
          </h1>
          <p>
            <xsl:value-of select="current()/data[@alias='bodyText']"/>
          </p>
          <p>
            <xsl:value-of select="current()/@author"/>
          </p>
        </xsl:for-each>
      </xsl:template>

    You would just do the same but include a lot more properties for your 'page'. 

    HTH,
    Nik

  • Max Edwards 26 posts 50 karma points
    Mar 10, 2010 @ 13:13
    Max Edwards
    0

    You may want to remove the links in the above if you don't want to visit a specific news page.

    Also remove the part calling umbraco.library.StripHtml if you want your links to appear.

     

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 10, 2010 @ 13:16
    Nik Wahlberg
    0

    I should add that the following would be a good example of a node 'query':

    <xsl:variable name="documentTypeAlias" select="string('NewsItem')" />
    <xsl:variable name="itmNodes" select="umbraco.library:GetXmlAll()/descendant-or-self::node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1' and umbraco.library:DateGreaterThanOrEqualToday(data [@alias = 'newsDateField'])=1]" />

    Of which you would then do:

     

      <xsl:template match="/">
       
    <xsl:for-each select="$itmNodes">
         
    <h1>
           
    <xsl:value-of select="current()/@nodeName"/>
         
    </h1>
         
    <p>
           
    <xsl:value-of select="current()/data[@alias='bodyText']"/>
         
    </p>
         
    <p>
           
    <xsl:value-of select="current()/@author"/>
         
    </p>
       
    </xsl:for-each>
     
    </xsl:template>

    This will allow you to output ALL news items irregardless of your context.

    Cheers,
    Nik

  • Jesper Hauge 298 posts 487 karma points c-trib
    Mar 10, 2010 @ 13:20
    Jesper Hauge
    0

    I'd go with xslt on this one, since xslt is very well suited for querying for subpages, and displaying their content. 

    I'm assuming you have a parent page with some child newsitem pages. Here's some xlst to get you started:

    <?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" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
        <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <div id="newsList">
                <xsl:apply-templates select="$currentPage/node[@nodeTypeAlias='newsItem']" />
            </div>
        </xsl:template>
    
        <xsl:template match="node">
            <div class="newsItem">
                <h1><xsl:value-of select="./data[@alias='header']" /></h1>
                <xsl:value-of select="./data[@alias='bodyText']" disable-output-escaping="yes" />
                <p class="newsItemData">
                    Published at: <xsl:value-of select="umbraco.library:FormatDate(./@updateDate, 'MM/dd/yyyy')" /><br />
                    <a href="{umbraco.library:NiceUrl(./@id)}">Read more</a>
                </p>
            </div>
        </xsl:template>
    </xsl:stylesheet>

    This xslt is assuming the following:

    1. Your news item pages are all located beneath one single newslist page
    2. You're displaying the news items from the newslist page (i.e. the newslist page is the current page)
    3. Your news items doctype alias is "newsItem"
    4. Your newsitems contains properties with aliases "header" and "bodyText", and header is as Textstring and bodyText is a richtext editor.
    Regards
    Jesper Hauge

  • tesuji 95 posts 139 karma points
    Mar 10, 2010 @ 16:42
    tesuji
    0

    Thanks very much

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies