Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1199 posts 2567 karma points
    Nov 10, 2011 @ 20:29
    Amir Khan
    0

    Populate form value with nodeName

    Hi,

    What is the correct way to populate the "value" of a hidden form field with the current Node name?

     

        <input id="element_2" name="element_2" value="@nodeName" size="30" class="validate[optional]" type="hidden" />

    Thanks!

    Amir

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 10, 2011 @ 20:36
    Chriztian Steinmeier
    1

    Hi Amir,

    That's actually close to Razor syntax :-)

    No, seriously, you just need to wrap a couple of curlies around it:

    <input id="..." name="..." value="{@nodeName}" size="..." />

    If you're inside the root template (match="/") you'll need $currentPage as well:

    <input value="{$currentPage/@nodeName}" />

    /Chriztian 

  • Amir Khan 1199 posts 2567 karma points
    Nov 10, 2011 @ 20:38
    Amir Khan
    0

    Thank you Chriztian!

    I also found that you can do it this way:

     

    <xsl:attribute name="value">
          <xsl:value-of select="@nodeName"/><xsl:value-of select="$currentPage/@nodeName" />
       </xsl:attribute>
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 10, 2011 @ 21:10
    Chriztian Steinmeier
    0

    You're absolutely right - though it's clunkier, it has its use when you don't know the name of the attribute you're creating, e.g.:

    <a href="#">
        <xsl:attribute name="data-{keyName}">
            <xsl:value-of select="$queryValue" />
        </xsl:attribute>
    </a>

    - or if you need to set or override an attribute only when a certain condition is met:

    <li>
        <!-- Only add class on uneven nodes -->
        <xsl:if test="position() mod 2 = 1">
            <xsl:attribute name="class">odd</xsl:attribute>
        </xsl:if>
        <a href="{umbraco.library:NiceUrl(@id)}">
            <!-- Override the href on the Home node -->
            <xsl:if test="self::Home">
                <xsl:attribute name="href">/</xsl:attribute>
            </xsl:if>
        </a>
    </li>
    

    /Chriztian 

     

  • 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