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
    Aug 11, 2010 @ 20:32
    JacoboPolavieja
    0

    Manage various parameters passed to a template

    Hello all!

     

    I have a template in which I call an XSLT file. My site is a news site and I want to be able to display the news in different formats depending on what's requested. For example, right now I have:

    - mydomain.com/news.aspx?tag="Michael Jordan" -> this would display all news that have the tag "Michael Jordan" (this is already achieved ;)).

    The problem is that I want to have things like:

    - mydomain.com/news.aspx?country="USA" -> this would display all news that have its "country" attribute set to "USA".

    - mydomain.com/news.aspx?competition="NBA" -> this would display all news that have its "competition" attribute set to "NBA".

     

    On the "news" template I just have the call to the macro which does something like:

    <xsl:if test="not(umbraco.library:Request('tag') = '')"> <!-- We have a tag passed as argument -->
    <!-- list all news with the specified tag -->
    </xsl:if>
    <xsl:if test="umbraco.library:Request('tag') = '' "> <!--We don't have tag argument -->
    <!-- list all news -->
    </xsl:if>

    If I have to control several possible arguments the thing goes nasty... So my questions are:

    1. Isn't there a better way to manage arguments/parameters?

    2. How would I control each case separately (?tag, ?country, ?competition) and even "concatenated" ones (?tag="Michael Jordan"&?country="USA") ? (The syntax is probably wrong, have never done something like that).

     

    I don't know if it would be better to call the template with parameters as it shows in the end of this page: http://en.wikibooks.org/wiki/Umbraco/Various_useful_XSLT_methods_in_Umbraco , or if that should be used for something else, etc...

    Any hint would be of much help. Thank you so much!


  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 11, 2010 @ 21:14
    Chriztian Steinmeier
    1

    Hi JacoboPolavieja,

    I do a fair amount of this in the XSLT file for my "XML Dump" package - it accepts a bunch of parameters in the QueryString and acts accordingly - you can take a look at how I do that in there, and get some ideas... It's located here: http://our.umbraco.org/projects/developer-tools/xml-dump

    /Chriztian

     

  • JacoboPolavieja 62 posts 84 karma points
    Aug 17, 2010 @ 20:08
    JacoboPolavieja
    0

    Hi Chriztian and thanks for replying.

    After having looked your XMLDump I tried to do something similar with my XSLT, without much success. I then saw this: http://our.umbraco.org/wiki/reference/umbracolibrary/requestquerystring

    From that I understand that "requesquerystring" doesn't give me which parameter is asked but the value of a parameter. From that example on the wiki, I'm no trying to get the value "Hello", but what goes right after the "?" mark. In that example I would have, for example, "MyQueryString", "MyQueryString2", "MyQueryString3"... and that is what I'm trying to get.

    Am I missing something? From your XSLT file from XMLDump I "ported" to my own XSLT in the form of:

    <!-- Test if we can detect QueryString parameters -->
    <xsl:variable name="queryStringAvailable" select="function-available('umb:RequestQueryString')" />   
      <xsl:variable name="mainCountry">
        <xsl:if test="$queryStringAvailable">
          <xsl:value-of select="umb:RequestQueryString('mainCountry')" />
        </xsl:if>
      </xsl:variable>
      
      <xsl:choose><xsl:when test="$mainCountry">
        <p>HOLA</p>
      </xsl:when></xsl:choose>

    The result is that it always prints "HOLA".

     

    Am I doing something very wrong? Thanks a lot!

Please Sign in or register to post replies

Write your reply to:

Draft