Copied to clipboard

Flag this post as spam?

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


  • JacoboPolavieja 62 posts 84 karma points
    Jul 26, 2010 @ 19:49
    JacoboPolavieja
    0

    parameters tutorial?

    Hi!

    I know I am asking a lot so sorry for flooding the forum... :S.

    I'd just like to know if there's any tutorial explaining how to pass and get parameters through pages. I just want to pass a tag option to the page and display the nodes that have that tag or something else if there's no option passed.

    You know, the typical "news.aspx?tag=NBA" vs just "news.aspx".

    I did see the umbraco.tv video on the tags datatype, which seems exactly what I want. The problem is that what it's done in the video is to just output a list of nodes that have that tag or all of them if they haven't one, whereas I need to do some things before the xsl:foreach in case there's no tag option passed.

    This is the code used in the video:

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1'
    and (umbraco.library:Request('tag') = '' or contains(data [@alias = 'tags'],umbraco.library:Request('tag')))]">

    As I say, my problem is that, in case there's no tag option passed I first need to do some other operations before any xsl:for-each (which isn't done on all $currentPage/node anyway). I have tried to put two xsl:if with no success as I don't know how to exactly check if there's an argument passed to the page and see which one is it. The intention would be something like

    if there's no tag --> do my own operations.

    if there's a tag passed --> forget about my operations and list all the nodes tagged with the tag passed as argument.

    So, to not bother anyone more, is there any other video I haven't checked or any other tutorial that goes step by step through the process of using parameters?

    Thanks!

  • Sascha Wolter 615 posts 1101 karma points
    Jul 27, 2010 @ 18:12
    Sascha Wolter
    0

    Hi Jacobo,

    no worries. :) Based on your description the following should be able to produce the result:

    <xsl:choose>

        <xsl:when test="umbraco.library:Request('tag') = '' ">

            [do your own operations here]

        </xsl:when>

        <xsl:otherwise>

          [list nodes as above]

        </xsl:otherwise>

    </xsl:choose>

    This obviously is an exclusive arrangement, so if you just want to perform a couple of operations AND list the nodes you can add an if statement before listing the nodes, like

    <xsl:if test="umbraco.library:Request('tag') != '' ">

       [do your own stuff here]

    </xsl:if>

    Hope that helps,

    Sascha

  • JacoboPolavieja 62 posts 84 karma points
    Aug 02, 2010 @ 12:29
    JacoboPolavieja
    0

    Hello Sascha and thanks for helping! Sorry for not answering earlier but I've been away for a few days without Internet connection.

     

    Following your post, I haven't been able to exactly accomplish my mission :). I now have:

    <xsl:choose>
       <xsl:when test="umbraco.library:Request('tag') = '' ">
    <!-- Do my operations and output successfully -->
       </xsl:when>
       <xsl:otherwise>
       <ul>
            <p>Hello world?</p>
    <!-- <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1' and (umbraco.library:Request('tag') = '' or contains(data [@alias = 'tags'],umbraco.library:Request('tag')))]"> -->
     <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1' and (umbraco.library:Request('tag') = '' or contains(data [@alias = 'tags'],umbraco.library:Request('tag')))] ">
        <li>
           <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>

        </xsl:otherwise>

    </xsl:choose>

    I am still not able to list the nodes which have the passed tag with any of the for-each statements above. I have also tried eliminating the umbraco.library:Request('tag') = '' , with the same result: no listing.

    I did put the "Hello world?" to see if it at least reachs there and it effectively does, so it's not a matter on the conditional block.

    Anything I'm missing?

     

    Thanks a lot!

  • Sascha Wolter 615 posts 1101 karma points
    Aug 02, 2010 @ 13:10
    Sascha Wolter
    0

    Hi Jacobo,

    I can't see anything why the first statement shouldn't work. I assume the nodes you want to display sit directly under the node where the Xslt file is used? The alias of the property is 'tags' and you are using Umbraco v 4.0.*? Just triple checking.

    I would suggest trying to eliminate one possible error after the other:

    replace <p>Hello world?</p> with 
    requested tag: |<xsl:value-of select="umbraco.library:Request('tag')" />|

    just to see if the tag string from the request gets through okay of if there are any encoding issues etc.

    Then maybe do something simple first and output all child nodes with their node name, their associated tags and if the query tag matches a node's tags:

    <xsl:for-each select="$currentPage/node">
        node name: <xsl:value-of select="@nodeName" />
        <br />
        tags: <xsl:value-of select="data[@alias='tags']" />
        <br />
        has query tag: <xsl:value-of select="contains(data[@alias='tags'], umbraco.library:Request('tag')" />
        <br /><br />
    </xsl:for-each>

    Can you have a go with the above and let me know what that gives you?

    And you are right, you definitely don't need the (umbraco.library:Request('tag') = '' statement as that has been taken care of by the outer choose statement.

    Sascha

  • JacoboPolavieja 62 posts 84 karma points
    Aug 02, 2010 @ 16:02
    JacoboPolavieja
    0

    Hello again and thanks for the interest!

     

    About the triple check: The nodes are child types of the document type from which template I call the XSLT file; is that all right or should I look somewhere else. The property I have realised now is not called simply "tags" but "thm_new_tags" (the nodes are "thm_new"), more on this below. I am using Umbraco 4.5, that's why I changed the xsl:for-each statement... is there anything else I should do?

     

    Copypasting your code (I just had to had one more parenthesis before closing the select statement) , it outputs the passed tag all right. If don't change the for-each like below instead o the $currentPage/node it outputs nothing else, so I continue using it with the new way (as far as I've understood!). I've also tried putting the alias as "tags" as well as below "thm_new_tags". The output is the same... it outputs all the nodes but all of them with no tags associated and all with the "requested tag" as "false", even the news rightly associated with the specified tag (I double checked that). Here's how the code is now:

    <ul>
      <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias]">
      <li>
        <span>node name: <xsl:value-of select="@nodeName" /></span>
        <br />
        <span>tags: <xsl:value-of select="data[@alias='thm_new_tags']" /></span>
        <br />
        <span>has query tag: <xsl:value-of select="contains(data[@alias='thm_new_tags'], umbraco.library:Request('tag'))"></xsl:value-of></span>
        <br /><br />
      </li>
    </xsl:for-each>
    </ul>

    Knowing that the property is "thm_new_tags", and that I'm using Umbraco4.5... what can be missing in the picture? As I said, it does list all the nodes, but doesn't seem to be able to get their tags correctly...

     

    Thank you so much for helping!

  • Sascha Wolter 615 posts 1101 karma points
    Aug 02, 2010 @ 16:23
    Sascha Wolter
    0

    Hi Jacobo,

    as you are using 4.5 with the new XML structure (or have you turned the legacy XML structure on? more here) you don't need the data[@alias=...] part anymore, which means that instead of

    <xsl:value-of select="data[@alias='thm_new_tags'] />

    you can just use

    <xsl:value-of select="/thm_new_tags" />.

    Can you give that a try please?

    Sascha

  • JacoboPolavieja 62 posts 84 karma points
    Aug 03, 2010 @ 09:41
    JacoboPolavieja
    0

    Hi!

     

    Issue solved! Thanks for helping me down the road! The link you posted is something I've been looking for a while. I think I'm just confused how umbraco's documentation is spread through multiple sources.

    Anyway, I indeed needed to use "thm_new_tags", only that without the first slash "<xsl:value-of select="thm_new_tags" />".

    Just for the record in case someone arrives here some day, the final code goes like this:

     

    <xsl:choose>
       
    <xsl:when test="umbraco.library:Request('tag') = '' ">
        <!-- do my first listing here -->

        </
    xsl:when>
    <xsl:otherwise>
    <
    ul>
    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1' and (contains(thm_new_tags, umbraco.library:Request('tag')))] ">
    <li>
                         <span>node name: <xsl:value-of select="@nodeName" /></span>
                         <br />
                         <span>tags: <xsl:value-of select="thm_new_tags" /></span>
                         <br />
                         <span>has query tag: <xsl:value-of select="contains(thm_new_tags, umbraco.library:Request('tag'))"></xsl:value-of></span>
                         <br /><br />
                    </li>
             </xsl:for-each>
         </ul>
     </xsl:otherwise>
    </xsl:choose>

     

    Thanks a lot for all the interest in my problem, this forum is awesome in terms of helping each other. Cheers!

  • Sascha Wolter 615 posts 1101 karma points
    Aug 03, 2010 @ 12:09
    Sascha Wolter
    0

    You're very welcome, glad it worked out well in the end. :)

Please Sign in or register to post replies

Write your reply to:

Draft