Copied to clipboard

Flag this post as spam?

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


  • quolo 13 posts 25 karma points
    Aug 06, 2009 @ 23:20
    quolo
    0

    Append value from previous or referring node to value in current page

    I can't quite figure out how to accomplish this--I'm no developer, so bear with me.

    What I'm attempting to do is insert a value into a template that comes from the previous node the user was on.  I have a URL I'm generating on the destination page that can have a runtime parameter appended to it that I want to change based on the previous page.

    It sounds more complicated than it is.  Think of it this way:

    I have a list of movies on a page the user can choose from.  User person clicks on a movie:  Godzilla vs. Mothra.  They go to a detail page called "Godzilla vs. Mothra" that tells them how great this movie is.  The user now wants to buy some tickets to the movie, so they click "Buy Tickets" and go to a node in which I have my shopping cart in an IFrame.  The src url of the IFrame should show a static "Http://xxx.xxxxx.com/" and on the end of that URL I want to add "moviecode=yyy".  Moviecode is a property I have added to the "Godzilla vs. Mothra" node and all detail pages through that document type.

    All I know how to do is pull in values from CurrentPage.  XPath just seems to go up and down in structure, not forward/back in time.

    Is this possible?

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Aug 07, 2009 @ 14:03
    Douglas Robar
    0

    You're right, xpath is for node structure and doesn't know anything about "time".

    Personally, I'd create and update a cookie to keep some persistence for each user. Then you can grab the cookie value to send to the iframe's url. At least, according to how you've described the problem.

    What I would really do is structure my content tree something like this, with some of the docType names in parenthesis:

    - movies (movies)
    - - Godzilla vs. Mothra (movie)
    - - - details
    - - - trailer
    - - - reviews (reviews)
    - - - - review 1 (review)
    - - - - review 2 (review)
    - - Return of the King (movie)
    - - - details
    - - - trailer
    - - - reviews
    - - - - review 1
    - - - - review 2

    You get the idea. Basically, you always know what movie is being viewed at all times because you can use $currentPage/ancestor-or-self::node[@nodeTypeAlias = 'movie']/@nodeName to get the name of the movie from any of the detail pages below it.

    If you add a textstring property to the 'movie' document type that holds the moviecode for each movie you could make a short macro that generates your Buy Now button and link for you. Then you could insert the Buy Now macro in your templates or even in the Richtext editor. 

    <xsl:template match="/">
        <a href="http://example.com/moviecode={$currentPage/ancestor-or-self::node[@nodeTypeAlias='movie']/data[@alias='moviecode']}">Buy Now</a>
    </xsl:template>

    At least, that's who I would do it. You'll need to change your docType names and properties to match your site.

    cheers,
    doug.

     

     

  • dandrayne 1138 posts 2262 karma points
    Aug 07, 2009 @ 14:17
    dandrayne
    0

    In a property listing site we have an "arrange a viewing" contact form that users visit after clicking a button from the property detail page.  , such as

    <a href="{umbraco.library:NiceUrl(@idofcontactpage)}?property={$currentPage/data [@alias='propname']}">arrange a viewing</a>

    then in the contact page you can grab the querystring param in xslt using xslt and use it in xslt, pass to your iframe, javascript or whatever

    <xsl:value-of select="umbraco.library:RequestQueryString('property')" />
  • quolo 13 posts 25 karma points
    Aug 07, 2009 @ 17:01
    quolo
    0

    Firstly, thanks to both of you.  This is my first experience with the Umbraco suport forums and you gotta be pretty pleased when you get this kind of assistane so quickly.

    Tough call--I think I'll try Dandrayne's method first.  My current structure is like this:

    -- Now Playing (MovieList)

    ---- Godzilla vs. Mothra (MovieDetail)

    ---- Mothra vs. Oprah Winfrey (MovieDetail)

    ----  Oprah Winfrey vs. Winston Churchill

    --  Coming Soon (MovieList)

    ----  Attack of the Killer Okra (MovieDetail)

    ---- The Blob's Mother

    ----  Sixteen Candles

    --  Tickets & Showtimes (Doctype with a template in which there is an <iframe> to shopping cart)

     

    Though I'm likely going to have to change that structure altogether for a different reason.

     

    Since I'm not a programmer, I think I've made a basic oversight in trying to add a querystring param to my URL.  What I did was:

    I went into the MovieDetail template and tried to adapt my Buy Tickets link to Dandrayne's example.  I think I've done it wrong:

    <a href="/{umbraco.library:NiceUrl(1060)}?property={$currentPage/data [@alias='EMC']}" title="Buy Tickets for this film"><img src="http://cms.lincolnplazacinema.com/media/1352/buytickets.png" alt="buytickets" width="180" height="60" rel="400,268" /></a>

    I wasn't sure if NiceUrl(@idofcontactPage) should just have the numerical ID of the Tickets&Showtimes page or how I'm supposed to tell Umbraco which page is the target.  When clicked upon, the result is a 404 and this in the browser's url window:

    http://xxx.xxxxx.com/%7Bumbraco.library:NiceUrl%281060%29%7D?property={$currentPage/data%20[@alias=%27EMC%27]}

    Whoops.

     

     

  • dandrayne 1138 posts 2262 karma points
    Aug 07, 2009 @ 17:29
    dandrayne
    0

    ooh, let's see. First off the xslt needs to be in a macro, which is inserted into the template.  It won't render directly in the template unless you're using inline xslt or the new xsltresult package.  But i digress, best for now to stick it in a macro and embed the macro on your template.

    NiceUrl takes the id of the page that you want a link to and creates the correct url, so if my shopping cart iframe was embedded in the node with id 1060, id do something like the following (using the more verbose xslt style this time for clarity)

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

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

    <a>
    <xsl:attribute name="href">
    <xsl:text>
    <xsl:value-of select="umbraco.library:NiceUrl(1060)"/>?movie=<xsl:value-of select="current()/data [@alias='Moviecode']" />
    </xsl:text>
    </xsl:attribute>
    Get tickets for this
    </a>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

    This xslt makes a number of assumptions

    • That this xslt will be used in a macro placed on your movielist pages
    • That the movie detail nodes are stored directly under this page, and are node type alias of "MovieDetail"
    • That each movie detail node has a property called MovieCode

    Then on the page containing your shopping cart/iframe etc the following code will grab the "movie" query string value

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:variable name="moviecode" select="umbraco.library:RequestQueryString('movie')" />

    <iframe>
    <xsl:attribute name="src">
    <xsl:text>
    sourceofiframe.html?moviecode=<xsl:value-of select="$moviecode" />
    </xsl:text>
    </xsl:attribute>
    </iframe>

    </xsl:template>

    </xsl:stylesheet>

    Again, this code is completely untested but it should be fairly close to what you're after.  Each movie has a link that contains the moviecode, the page with the iframe catches the moviecode and appends it to the src attribute of the iframe.

    Hope this helps - once you get your head around the xslt you should be ok. 
    Dan

  • quolo 13 posts 25 karma points
    Aug 07, 2009 @ 19:47
    quolo
    0

    Thanks ever so much for the primer.  I'm in complete understanding about using a macro--should have figured that out on my own.

    I've been trying to resolve an error in the pasted code above (the first .xslt file) and, due to my XSLT inexperience, haven't yet figured out what the issue is.  The error is:

     

    Error occuredError in XSLT at line 25, char 33
    23:       <xsl:attribute name="href">
    24:       <xsl:text>
    25: >>>   <xsl:value-of select="umbraco.library:NiceUrl(1060)"/>?EMC=<xsl:value-of select="$currentPage/data [@alias='EMC']" /> <<<
    26:       </xsl:text>
    27:       </xsl:attribute>

    It's probably a syntax error or something I can't find.  Any thoughts?

  • quolo 13 posts 25 karma points
    Aug 07, 2009 @ 19:51
    quolo
    0

    Actually, allow me to repaste the error.  The version above shows one of my feeble attempt to figure out what I was doing wrong.

    Here's the original:

     

    Error occuredError in XSLT at line 22, char 33
    20:       <xsl:attribute name="href">
    21:       <xsl:text>
    22: >>>   <xsl:value-of select="umbraco.library:NiceUrl(1060)"/>?movie=<xsl:value-of select="current()/data [@alias='Moviecode']" /> <<<
    23:       </xsl:text>
    24:       </xsl:attribute>
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 07, 2009 @ 22:35
    Dirk De Grave
    0

    Hi quolo,

     

    Just a little change in your xslt required:

    <xsl:attribute name="href">
      <xsl:value-of select="umbraco.library:NiceUrl(1060)"/>
      <xsl:text>?movie=</xsl:text>
      <xsl:value-of select="current()/data [@alias='Moviecode']" />
    </xsl:attribute>

     

    Hope this helps.

     

    Regards,

    /Dirk

     

Please Sign in or register to post replies

Write your reply to:

Draft