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.
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:
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.
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 " "> ]> <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
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
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.
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:
This will allow you to output ALL news items irregardless of your context.
Cheers,
Nik
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 " "> ]> <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:
Jesper Hauge
Thanks very much
is working on a reply...
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.