Copied to clipboard

Flag this post as spam?

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


  • Fredrik 41 posts 161 karma points
    Jan 13, 2010 @ 14:51
    Fredrik
    0

    Show newslist on every node, included on newsarticles.

    Hello!

    I ran into this roadblock today:
    I am making a website that will always have a newslist on the left side of the page. I installed the Runway News Library as a start and it's working well.

    This is how it looks now:
    Newslist on homepage looks like this:
    - Newsarticle 1
     -Newsarticle 2
    - Newsarticle 3

    Newslist on any of the newsarticle looks like this:
    - Newsarticle ( this is the article I am browsing )

    I would like all the newsitem to show on newspages aswell, and not only the active like it does now.
    The macro is in Mastertemplate and imo I don't think it's there since it always show the active newsarticle.
    My guess, it's something missing from the xslt, but I am not sure what and where it should go.

    Anyone got any idea what will fix this? ;)


    Information:
    umbraco v 4.0.2.1 (Assembly version: 1.0.3441.17657)
    SQL Server 2008
    Windows Server 2008 SP2 64-bit
    IIS7

    Best Regards,
    Fredrik K

    Here is the RunwayNewsLibrary.xslt code (Sorry for long code, I chopped off some pieces so it wouldn't be so long)


    <!-- The Newspages to repeat over -->
    <xsl:variable name="documents" select="$currentPage/descendant-or-self::node [@nodeTypeAlias = 'RunwayNewspage']" />

    <!-- Number of characters to display in the preview -->
    <xsl:variable name="numCharsPreview">
    <xsl:choose>
    <xsl:when test="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'RunwayNewsLibrary']/data [@alias = 'numPreviewChars'] != '' and number($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'RunwayNewsLibrary']/data [@alias = 'numPreviewChars']) != 'NaN'">
    <xsl:value-of select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'RunwayNewsLibrary']/data [@alias = 'numPreviewChars']"/>
    </xsl:when>
    <xsl:when test="string(/macro/numCharsPreview) != ''">
    <xsl:value-of select="/macro/numCharsPreview"/>
    </xsl:when>
    <xsl:otherwise>66</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <!-- Text to display if there are no items -->
    <xsl:variable name="newsNoItems">
    <xsl:choose>
    <xsl:when test="umbraco.library:GetDictionaryItem('NewsNoItems') != ''">
    <xsl:value-of select="umbraco.library:GetDictionaryItem('NewsNoItems')"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:text></xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <!-- Paging Variables -->
    <xsl:variable name="numDocs" select="count($documents)"/>

    <xsl:variable name="numDisplay">
    <xsl:choose>
    <xsl:when test="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'RunwayNewsLibrary']/data [@alias = 'numDisplay'] != '' and number($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'RunwayNewsLibrary']/data [@alias = 'numDisplay']) != 'NaN'">
    <xsl:value-of select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'RunwayNewsLibrary']/data [@alias = 'numDisplay']"/>
    </xsl:when>
    <xsl:when test="string(/macro/numDisplay) != '' and number(/macro/numDisplay) != 'NaN'">
    <xsl:value-of select="/macro/numDisplay"/>
    </xsl:when>
    <xsl:otherwise>3</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="numPages" select="ceiling($numDocs div $numDisplay)"/>

    <xsl:variable name="queryPage" select="umbraco.library:RequestQueryString('page')"/>
    <xsl:variable name="page">
    <xsl:choose>
    <xsl:when test="$queryPage != ''">
    <!-- Insert page validation code here -->
    <xsl:choose>
    <xsl:when test="string(number($queryPage)) = 'NaN' or $queryPage &lt;= 0">
    <xsl:value-of select="1"/>
    </xsl:when>
    <xsl:when test="$queryPage &gt; $numPages">
    <xsl:value-of select="$numPages"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$queryPage"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:otherwise>1</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <!-- Main Method -->
    <xsl:template match="/">
    <xsl:value-of select="umbraco.library:RegisterStyleSheetFile('umbracoNews', '/css/umbracoNews.css')"/>
    <div id="news-items">
    <xsl:choose>
    <xsl:when test="$numDocs &gt; 0">
    <xsl:call-template name="RenderNodes">
    <xsl:with-param name="documents" select="$documents"/>
    <xsl:with-param name="page" select="$page"/>
    <xsl:with-param name="numDisplay" select="$numDisplay" />
    </xsl:call-template>

    <!-- Display navigation if number of items greater than number to display per page -->
    <xsl:if test="$numDocs &gt; $numDisplay">
    <div id="news-navigation">
    <xsl:call-template name="RenderNavigation">
    <xsl:with-param name="numPages" select="$numPages" />
    <xsl:with-param name="page" select="$page" />
    </xsl:call-template>
    </div>
    </xsl:if>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$newsNoItems" />
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:template>

    <!-- Renders the list containing the Documents -->
    <xsl:template name="RenderNodes">
    <xsl:param name="documents" />
    <xsl:param name="page" />
    <xsl:param name="numDisplay" />

    <xsl:variable name="startPosition" select="($page * $numDisplay - $numDisplay) + 1" />
    <xsl:variable name="endPosition" select="$page * $numDisplay" />

    <ul>
    <xsl:for-each select="$documents">
    <xsl:sort select="./@createDate" order="descending" />

    <xsl:variable name="focusImage" select="./data [@alias = 'FocusImage']"/>

    <xsl:if test="position() &gt;= $startPosition and position() &lt;= $endPosition">
    <li class="news-item">
    <xsl:if test="position() mod 2 = 1">
    <xsl:attribute name="class">alternate</xsl:attribute>
    </xsl:if>
    <div>
    <xsl:choose>
    <xsl:when test="string($focusImage) != ''">
    <xsl:attribute name="class">text-medium-image</xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
    <xsl:attribute name="class">text-no-image</xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
    <h3>
    <a href="{umbraco.library:NiceUrl(./@id)}">
    <xsl:value-of select="./@nodeName"/>
    </a>
    </h3>
    <p>
    <xsl:value-of select="umbraco.page:GetPreviewText(umbraco.library:StripHtml(./data [@alias = 'bodyText']), $numCharsPreview)" disable-output-escaping="yes"/>
    </p>
    <span class="read-more">
    <a href="{umbraco.library:NiceUrl(./@id)}">
    <xsl:value-of select="umbraco.library:GetDictionaryItem('ReadMore')" />
    </a>
    </span>
    </div>
    <xsl:if test="string($focusImage) != ''">
    <xsl:variable name="mediaId" select="$focusImage" />
    <xsl:if test="$mediaId &gt; 0">
    <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, false)" />
    <div class="image-medium-frame">
    <div class="image-medium">
    <img alt="{$media/@nodeName}" src="{$media/data [@alias = 'umbracoFile']}" />
    </div>
    </div>
    </xsl:if>
    </xsl:if>
    </li>
    </xsl:if>
    </xsl:for-each>
    </ul>

    </xsl:template>


    <!-- Renders the navigation links -->
    <xsl:template name="RenderNavigation">
    <xsl:param name="numPages"/>
    <xsl:param name="page"/>

    <ul>
    <xsl:if test="$page &gt; 1">
    <li class="less">
    <a id="previous">
    <xsl:if test="$page &gt; 1">
    <xsl:attribute name="href">
    <xsl:text>?page=</xsl:text>
    <xsl:value-of select="$page - 1"/>
    </xsl:attribute>
    </xsl:if>
    <xsl:value-of select="$prevText"/>
    </a>
    </li>
    </xsl:if>

    <xsl:call-template name="RenderPageLinks">
    <xsl:with-param name="numPages" select="$numPages"/>
    <xsl:with-param name="page" select="$page"/>
    <xsl:with-param name="current" select="1" />
    </xsl:call-template>
    <xsl:if test="$page &lt; $numPages">
    <li class="more">
    <a id="next">
    <xsl:if test="$page &lt; $numPages">
    <xsl:attribute name="href">
    <xsl:text>?page=</xsl:text>
    <xsl:value-of select="$page + 1"/>
    </xsl:attribute>
    </xsl:if>
    <xsl:value-of select="$nextText"/>
    </a>
    </li>
    </xsl:if>
    </ul>
    </xsl:template>

    <!-- Renders the list of pages -->
    <xsl:template name="RenderPageLinks">
    <xsl:param name="numPages"/>
    <xsl:param name="page"/>
    <xsl:param name="current"/>

    <li>
    <xsl:if test="$page = $current">
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>
    <a>
    <xsl:attribute name="href">
    <xsl:text>?page=</xsl:text>
    <xsl:value-of select="$current"/>
    </xsl:attribute>
    <xsl:value-of select="$current"/>
    </a>
    </li>

    <xsl:if test="$current &lt; $numPages">
    <xsl:call-template name="RenderPageLinks">
    <xsl:with-param name="numPages" select="$numPages"/>
    <xsl:with-param name="page" select="$page"/>
    <xsl:with-param name="current" select="$current + 1" />
    </xsl:call-template>
    </xsl:if>

    </xsl:template>

    <msxsl:script language="CSharp" implements-prefix="umbraco.page">
    <![CDATA[
    public static string GetPreviewText(string text, int numCharsToDisplay)
    {
    if (text.Length > numCharsToDisplay)
    {
    int cutPos = text.IndexOf(".", numCharsToDisplay);

    if(cutPos > 0)
    text = text.Substring(0, cutPos + 1);
    }
    return text;
    }

    ]]>
    </msxsl:script>
    </xsl:stylesheet>

     

  • 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