Copied to clipboard

Flag this post as spam?

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


  • jefferycxl 35 posts 83 karma points
    Aug 11, 2009 @ 10:24
    jefferycxl
    0

    How to set current page variable to a chosen page

    Hi guys and girls:

    I knew that you can query umbraco to generate a list of subpages of a parent page, my question is how can you set the value of $currentPage to one of these parent pages, so the following code will generate a list of subpage only under that chosen parent page.

    Or, if possible, how can I query umbraco to generate a list of pages with certain document types?

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    <br/>
    <xsl:value-of select="data [@alias = 'metaText']"/>
    </xsl:if>
    </li>
    </xsl:if>
    </xsl:for-each>

     

    Thanks & Regards,

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 11, 2009 @ 10:31
    Warren Buckley
    0

    It's probably not best to re-assign currentPage variable as may cause problems at a later date for readability etc...

    The code below will display nodes where the nodeType is of yourDocTypeAlias

    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'yourDocTypeAlias']">
       <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
       </a>
    </xsl:for-each>

    The code below will display nodes where the nodeType is NOT of yourDocTypeAlias

    <xsl:for-each select="$currentPage/node [@nodeTypeAlias != 'yourDocTypeAlias']">
       <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
       </a>
    </xsl:for-each>

    I hope I understood your question correctly.
    Warren :)

  • Masood Afzal 176 posts 522 karma points
    Aug 11, 2009 @ 10:32
    Masood Afzal
    0

    Following code will list all documents of a type

    <

    xsl:param name="currentPage"/>

     

    <!-- document type alias e.g. NewsDetail -->

     

    <

    <

    xsl:variable name="documentTypeAlias" select="string('NewsDetail')"/>

     

    <!-- start from root/home -->

     

    <

    <

    xsl:variable name="rootPage" select="$currentPage/ancestor-or-self::node[@level = 1]"/>

     

    <

    xsl:template match="/">

     

    <

    xsl:for-each select="$rootPage/descendant::node [@nodeTypeAlias = $documentTypeAlias]">

    <!--

    list each document -->

    </

    xsl:for-each>

     

    </

    xsl:template>

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Aug 11, 2009 @ 10:33
    Warren Buckley
    0

    I forgot to mention that this code will display child nodes of the currentPage/node you are on.

  • Masood Afzal 176 posts 522 karma points
    Aug 11, 2009 @ 10:47
    Masood Afzal
    0

    <xsl:param name="currentPage"/>

     

    <!--

    start from root -->

    <

    xsl:variable name="rootPage" select="$currentPage/ancestor-or-self::node[@level = 1]"/>

     

    <!-- start from current page -->

    <!--

     

    <xsl:variable name="rootPage" select="$currentPage/*"/>

    -->

     

    <!--

    document type alias e.g. NewsDetail -->

    <

    xsl:variable name="documentTypeAlias" select="string('NewsDetail')"/>

     

    <

    xsl:template match="/">

    <

    ul>

    <

    xsl:for-each select="$rootPage/descendant::node [@nodeTypeAlias = $documentTypeAlias]">

    <

    li>

    <

    a href="{umbraco.library:NiceUrl(@id)}">

    <

    xsl:value-of select="@nodeName"/>

    </

    a>

    </

    li>

    </

    xsl:for-each>

    </

    ul>

    </

    xsl:template>

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Aug 11, 2009 @ 11:20
    Douglas Robar
    0

    What you want to do is easily done. Simply create a new xslt macro (right-click on the XSLT Files item in the developer section of umbraco). Give the xslt a name and select one of the pre-defined templates. In your case, you'd probably want pages from a 'changable source' or 'by docType'. The various built-in templates are a great start to most situations.

    cheers,
    doug.

  • jefferycxl 35 posts 83 karma points
    Aug 14, 2009 @ 10:01
    jefferycxl
    0

    Warren Buckley, Masood Afzal and Douglas Robar

    Thanks very much to all you guys. All your solution helped, I just have one more question, how can I replace

    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">

    which only display sub pages of a parent node with select="$variable that can display all document with [@nodeTypeAlias = $documentTypeAlias

    Once again.

    Thanks & Regards,

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 14, 2009 @ 10:06
    Dirk De Grave
    0

    Hi jefferycxl,

    Following snippet should do:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($variable)/node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">

    All you do is get the xml fragment from parent node (GetXmlNodeById(parentId) and iterate its children.

     

    Hope this helps.

    Regards,

    /Dirk

     

  • jefferycxl 35 posts 83 karma points
    Aug 14, 2009 @ 10:13
    jefferycxl
    0

    Sorry guys,  Masood Afzal, I misunderstand your code, I used your code $currentPage/ancestor-or-self::root//node and it worked beautifully.

    Please ignore my previous question.

    Thanks

     

  • jefferycxl 35 posts 83 karma points
    Aug 14, 2009 @ 11:08
    jefferycxl
    0

    Hi Dirk De Grave

    Thanks very much for the help.

    Love the umbraco forum !

Please Sign in or register to post replies

Write your reply to:

Draft