Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Aug 16, 2011 @ 12:54
    Kasper Dyrvig
    0

    If statement and Related Link

    Hi all

    I'm puzzeling with the Related Links data type... The goal is to view the content of the childs of currentPage. Some of the childs contains both external and internal links made with the Related Links data type. But in my foreach loop I can't get the links out.

    I have tried to do it with a copy-of on a node that contains links, so I am sure that the markup code works. As far I can see the problem is in the if statenment checking if serviceRelated contains enything. But I'm not sure what to do to make it work?

    <table cellpadding="0" cellspacing="0">
      <xsl:for-each select="umbraco.library:GetXmlNodeById($subject)/* [@isDoc and umbracoNaviHide != 1 and @level = 6]">
        <tr class="serviceQ">
          <td>Question</td>
          <td><p><xsl:value-of select="serviceQuestion"/></p></td>
        </tr>
        <tr class="serviceA">
          <td>Answar</td>
          <td>
            <xsl:value-of select="bodyText" disable-output-escaping="yes"/>
            <xsl:if test="serviceRelated != ''">
              <xsl:for-each select="serviceRelated [not(@isDoc)]/links/link">
                <p><a>&#8250; <xsl:attribute name="href"><xsl:choose><xsl:when test="@type = 'internal'"><xsl:value-of select="umbraco.library:Replace(umbraco.library:NiceUrl(@link), '.aspx', '')"/></xsl:when><xsl:otherwise><xsl:value-of select="@link"/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:value-of select="@title"/></a></p>
              </xsl:for-each>
            </xsl:if>
          </td>
        </tr>
      </xsl:for-each>
    </table>

    Can some one help me out? Thanks

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 16, 2011 @ 13:06
    Fuji Kusaka
    0

    Hi Kasper

    What you can try is create a XSLT under the developer section and try to add the Macros to you Template.  Then just replace your documentType Alias 

    <xsl:variable name="propertyAlias" select="string('YourAlias')"/>

    This worked for me.

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 16, 2011 @ 13:22
    Kasper Dyrvig
    0

    Sorry I wasn’t clear enough... the code posted is from the xslt and it is placed in the template. 

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 16, 2011 @ 14:06
    Fuji Kusaka
    0

    Kasper, thats what i meant earlier, you could try creating an XSLT and use the choose Related Links from the drop down menu. And replaced your documentType Alias as you named it and placed it in your template.

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 16, 2011 @ 15:21
    Kasper Dyrvig
    0

    Okaaay... now I understand what you mean. I have done that now. But how can that help me? The result is no different...

    My code now:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($subject)/* [@isDoc and umbracoNaviHide != 1 and @level = 6]">
      <table cellpadding="0" cellspacing="0" class="serviceQATable" id="{@id}">
      <tr class="serviceQ">
        <td>Sprøgsmål</td>
        <td><p><xsl:value-of select="serviceQuestion"/></p></td>
      </tr>
      <tr class="serviceA">
        <td>Svar</td>
        <td>
          <xsl:value-of select="bodyText" disable-output-escaping="yes"/>
            <class="serviceGoto">
              <xsl:for-each select="./* [name() = 'serviceRelates' and not(@isDoc)]/links/link">
                <a>&#8250; <xsl:attribute name="href"><xsl:choose><xsl:when test="@type = 'internal'"><xsl:value-of select="umbraco.library:Replace(umbraco.library:NiceUrl(@link), '.aspx', '')"/></xsl:when><xsl:otherwise><xsl:value-of select="@link"/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:value-of select="@title"/></a><br />
              </xsl:for-each>
            </p>
            <xsl:if test="serviceVideolink != ''">
              <class="serviceGoto"><class="serviceOpenVideo">&#8250; Se videoguide</a></p>
              <div class="serviceVideo"><iframe width="550" height="343" src="http://www.youtube.com/embed/{serviceVideolink}?rel=0" frameborder="0"></iframe></div>
            </xsl:if>
          </td>
        </tr>
      </table>
    </xsl:for-each>
  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 16, 2011 @ 16:10
    Fuji Kusaka
    0

    Hi again Kasper, can you tell me what is the name of your DocumentType Alias you used for your Related Links?

    If is the SERVICEVIDEOLINK then try making use of the XSLT Related Links already available under the Developer Section. You should get some code like that

    <xsl:param name="currentPage"/>
      
      <!-- Input the related links property alias here -->
      <xsl:variable name="propertyAlias" select="string('links')"/>
      
      <xsl:template match="/">

        <!-- The fun starts here -->
        <ul>
          <xsl:for-each select="$currentPage/* [name() = $propertyAlias and not(@isDoc)]/links/link">
            <li>
              <xsl:element name="a">
                <xsl:if test="./@newwindow = '1'">
                  <xsl:attribute name="target">_blank</xsl:attribute>
                </xsl:if>
                <xsl:choose>
                  <xsl:when test="./@type = 'external'">
                    <xsl:attribute name="href">
                      <xsl:value-of select="./@link"/>
                    </xsl:attribute>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:attribute name="href">
                      <xsl:value-of select="umbraco.library:NiceUrl(./@link)"/>
                    </xsl:attribute>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="./@title"/>
              </xsl:element>
            </li>
          </xsl:for-each>
        </ul>

          </xsl:template>

     

    Then here you can change your property alias to 

    <xsl:variable name="propertyAlias" select="string('serviceVideolink')"/>


    See if you are getting the value you inserted in your Content Section, then just add all your other fields.

     

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 17, 2011 @ 10:52
    Kasper Dyrvig
    0

    The docemnettype containing the Related links is called serviceRelates.

    <xsl:for-each select="./* [name() = 'serviceRelates' and not(@isDoc)]/links/link">
      <a>&#8250; <xsl:attribute name="href"><xsl:choose><xsl:when test="@type = 'internal'"><xsl:value-of select="umbraco.library:Replace(umbraco.library:NiceUrl(@link), '.aspx', '')"/></xsl:when><xsl:otherwise><xsl:value-of select="@link"/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:value-of select="@title"/></a><br />
    </xsl:for-each>
  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 17, 2011 @ 11:11
    Fuji Kusaka
    0

    did you change this your variable propertyAlias to

    <xsl:variablename="propertyAlias"select="string('serviceRelates')"/>

     

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 23, 2011 @ 12:40
    Kasper Dyrvig
    0

    Nooo... stupid me.

    It turns out that the property is called serviceRelated, not serviceRelates. Now it works...

    <xsl:for-each select="serviceRelated/links/link">
      <a><xsl:attribute name="href"><xsl:choose><xsl:when test="@type = 'internal'"><xsl:value-of select="umbraco.library:Replace(umbraco.library:NiceUrl(@link), '.aspx', '')"/></xsl:when><xsl:otherwise><xsl:value-of select="@link"/></xsl:otherwise></xsl:choose></xsl:attribute>&#8250; <xsl:value-of select="@title"/></a><br />
    </xsl:for-each>

    Thanks for your help and patience.

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 23, 2011 @ 12:45
    Fuji Kusaka
    0

    Hi Kasper,

    Good you got it working  :)

     

     

Please Sign in or register to post replies

Write your reply to:

Draft