I would like the "What's New" page to have the same content as the "most recent news" node, but without redirecting. I'm also trying to have a "next" button on the "What's New" page that will skip directly to the "second most recent news" (so that there won't be any duplicates for the user).
I can get everything to work fine and page back and forth on the child nodes, but I'm having trouble with the "What's New" parent node.
You might want to post your XSLT so we can get a better idea of your problem, but to get a specific news item I believe you can add [#] to the end of your XPath filter. Something like this might work:
<!-- Link to the second news item --> <xsl:variable name="secondNewsItem" select="$currentPage/NewsItem [2]"/> <a href="{umbraco.library:NiceUrl($secondNewsItem/@id)}">Next (<xsl:value-of select="$secondNewsItem/@nodeName"/>)</a>
<!-- Show the first news item --> <xsl:variable name="firstNewsItem" select="$currentPage/NewsItem[1]"/> <xsl:value-of select="$firstNewsItem/@nodeName"/>
Of course this assumes they are already in the order you want...are you wanting to sort them by date and get the most recent, or are they already ordered correctly in the node tree?
After digging around, it seems like the renderTemplate feature would be ideal for my needs, but I can't get it to work. This is what I have, but it's not working (not picking up the first child node's ID and template and passing it on to the current page to display). I hard-coded the node ID and template ID into the renderTemplate macro to test it, and it works fine that way, but of course that won't work long term because the first child node will be different every time a newws story is added.
Thanks Rich! That worked well.. not exactly what I was planning on doing (wasn't planning on actually redirecting the page), but works just fine anyway.
Render first child node on parent page
I have a "news" section, set up as follows:
What's New (parent node):
I would like the "What's New" page to have the same content as the "most recent news" node, but without redirecting. I'm also trying to have a "next" button on the "What's New" page that will skip directly to the "second most recent news" (so that there won't be any duplicates for the user).
I can get everything to work fine and page back and forth on the child nodes, but I'm having trouble with the "What's New" parent node.
Any suggestions are greatly appreciated.
Hi Laura,
You might want to post your XSLT so we can get a better idea of your problem, but to get a specific news item I believe you can add [#] to the end of your XPath filter. Something like this might work:
Of course this assumes they are already in the order you want...are you wanting to sort them by date and get the most recent, or are they already ordered correctly in the node tree?
-Tom
After digging around, it seems like the renderTemplate feature would be ideal for my needs, but I can't get it to work. This is what I have, but it's not working (not picking up the first child node's ID and template and passing it on to the current page to display). I hard-coded the node ID and template ID into the renderTemplate macro to test it, and it works fine that way, but of course that won't work long term because the first child node will be different every time a newws story is added.
<xsl:param name="currentPage"/>
<xsl:param name="renderFirstSubnode" select="/macro/renderFirstSubnode"/>
<xsl:variable name="PageId">
<xsl:choose>
<xsl:when test="$renderFirstSubnode='true'">
<xsl:value-of select="$currentPage/node/@id"/>
</xsl:when>
<xsl:when test="$currentPage/data [@alias = 'RenderTemplate']!=''">
<xsl:value-of select="$currentPage/data [@alias = 'RenderTemplate']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/macro/pageId"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="TemplateId">
<xsl:choose>
<xsl:when test="/macro/templateId != ''">
<xsl:value-of select="/macro/templateId"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:GetXmlNodeById($PageId)/./@template"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="string($PageId)!='' and string($TemplateId)!=''">
<xsl:value-of select="umbraco.library:RenderTemplate($PageId, $TemplateId)" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>An error has occured.</xsl:text>
<br />
<xsl:text>Please contact webmaster to resolve this error.</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Would this work? it sounds to me as though your renderFirstSubnode isn't returning anything
<xsl:variable name="renderFirstSubnode"select="$currentPage/node[position()=1]"/>
take a look at this post it may also help
http://our.umbraco.org/forum/developers/xslt/2834-Redirect-to-first-child-node-in-xslt
I would add a template named something like "Redirect to first child"
Then in that template add this code
<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
var current = umbraco.NodeFactory.Node.GetCurrent();
if (current != null)
{
var child = current.ChildrenAsList.FirstOrDefault();
if (child != null)
{
var url = child.Url;
if (!string.IsNullOrEmpty(url))
{
Response.Redirect(url, true);
}
}
}
}
</script>
Then allow the parent node to use this template, select the template for 'What's new', then you should be done.
Rich
Thanks Rich! That worked well.. not exactly what I was planning on doing (wasn't planning on actually redirecting the page), but works just fine anyway.
is working on a reply...