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.
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:
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.
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
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:
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)
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
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?
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?
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.
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.
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
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
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:
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.
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)
This xslt makes a number of assumptions
Then on the page containing your shopping cart/iframe etc the following code will grab the "movie" query string value
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
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:
It's probably a syntax error or something I can't find. Any thoughts?
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:
Hi quolo,
Just a little change in your xslt required:
Hope this helps.
Regards,
/Dirk
is working on a reply...