Copied to clipboard

Flag this post as spam?

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


  • Roger Hughes 55 posts 88 karma points
    Feb 03, 2010 @ 15:17
    Roger Hughes
    0

    XSLT sub menu based on a template

    Hi all,

    I have a sub menu generated from a macro.
    I am looking to populate the menu if a specific template is used rather than a content node.

    For example. I have a template called portal. Portal can be applied to any content textpage. In the template is a set of buttons. These buttons need to display all the pages that use the portal template rather than displaying pages that belong to a specific parent node.

    I thought that if the templates are saved to an XML file when they are generated then this would be simple because they would have a node id.

    Is this possible?

    Thanks

    Roger

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    Feb 03, 2010 @ 15:25
    Douglas Robar
    1

    You can use the @template for the node of the page in question. Something like...

    <xsl:if test="$currentPage/@template = 1234">
    ... do something special ...
    </xsl:if>

    As I recall, the @template is the id of the template not its alias. If you want to use the alias you'd need to write a quick little xslt extension or use some inline c# in your xslt to get the id from the template alias:

    umbraco.cms.businesslogic.template.Template.GetByAlias('alias').Id

    cheers,
    doug.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 15:25
    Thomas Höhler
    0

    for xslt you can react on:

    <xsl:if test="$currentPage/@nodeType = YOUR_NODE_TYPE_ID" />

    hth, Thomas

  • Roger Hughes 55 posts 88 karma points
    Feb 03, 2010 @ 16:00
    Roger Hughes
    0

    Thanks guys,

    Is there a way of changing this:

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

    from documentTypeAlias to a specific document type or template? Something like documentTypeAlias=1234

    Thanks

    Roger

  • Roger Hughes 55 posts 88 karma points
    Feb 03, 2010 @ 16:06
    Roger Hughes
    0

    Ok, I have found in the XML the node type alias that I need:

    nodeTypeAlias="dtMainPortal

    am i right in thinking that this is set like:

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

    Thanks!

    Roger

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 03, 2010 @ 16:07
    Thomas Höhler
    0

    document type:

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

    template:

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

    my example from before had been false, it has to be the @template like Doug mentioned...

    Thomas

  • Roger Hughes 55 posts 88 karma points
    Feb 03, 2010 @ 16:16
    Roger Hughes
    0

    Thanks guys. youve been a big help. I made an error with the umbracoNaviHide

    This has worked perfectly:

    <xsl:for-each select="$currentPage/node[@nodeTypeAlias = 'dtMainPortal']">

        <li>
            <a class="portal{data[@alias = 'buttonType']}" href="{umbraco.library:NiceUrl(@id)}">
                <span class="btntitle"><xsl:value-of select="data [@alias = 'btnName']"/></span>
                <span class="btnstrapline"><xsl:value-of select="data [@alias = 'btnStrapline']"/></span>
            </a>
        </li>

    </xsl:for-each>

    many thanks again

    Roger

  • Heather Floyd 531 posts 787 karma points MVP 2x c-trib
    Feb 25, 2010 @ 02:56
    Heather Floyd
    0

    I came to this post via a search for "xslt template alias", so if anyone is interested in the code necessary to get the alias (name) of a template via XSLT, here is the code:

    <msxml:script language="C#" implements-prefix="fi">
    <msxml:assembly name="cms"/>
    <msxml:assembly name="businesslogic"/>
    <msxml:using namespace="umbraco.cms.businesslogic"/>
    <msxml:using namespace="umbraco.cms.businesslogic.template"/>
    <![CDATA[
    public string GetTemplateAlias(int TemplateID)
    {
        Template templateLookup = Template.GetTemplate(TemplateID);
        return templateLookup.Alias;
    }
    ]]>
    </msxml:script>

    I used this in a package I just uploaded, if you want to see the whole xslt: Dynamic Body Tag

    I hope this helps someone else.

    ~Heather

  • 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