Hi, this seems extremely simple but a Google search shows me about 20 different and varied examples which i can't get any to work. I am just trying to check a parameter for my text pages, if the value exists then add some javascript code to redirect the user. Here is my example code:
the IF TEST always executes as TRUE so no matter what, it adds the redirect code even when there is no value and that just puts the page in a loop. Please someone help me i have been programming for decades but i am new to XSLT and this is embarassing that i can't get something this easy to work. Please help.
This should work for you. Remember that when you write the URL you will redirect to in the Umbraco field you need to remeber the http://, so like should be like e.g http://www.google.com
Hmm okay thanks for the reply Dennis, it looks like i am missing some fundamental information here because when i add the code to my Textpage template it shows the code in my HTML source and doesn't execute the code. Is it even possible to add XSLT code to a template or should i be using Razor? Sorry for the questions i am very new to this and I appreciate your help.
Okay I will try to guide you step by step so we are get it work for you.
1. Add the field on the document type for e.g frontpage. Go the setting section --> Document type (I have made a screenshot)
2. Then we need to create a XSLT file. Go to developer section, then right click on the XSLT folder. Give the file a name (e.g Redirect) and choose clean. There are some build in templates for e.g navigation and so on. When you create the file don´´t remove the tick in Create Macro.
When you have created the XSLT plaste in this code, and then save the file:
3. Go back to the settings section choose the templates forlder and choose the template where you what the redirect. It could be on the frontpage. (In my example I have choosen the frontpage)
Then click at the button or the click at the arrow that i have marked. When you done that you chould get at list of your macros, could be XSLT or Razor. There you need to find the macro with the name you gave your XSLT when you created it.
When click okay and save the template. After that this should be added in your template.
4. Now go to content page and choose a page with the field where you can add the URL. In my example I added the field to the frontpage, and now I write the URL that the page should redirect to. (See sreenshot)
I hope these screenshot will make it easier to you to get the redirect working.If you have any question about this keep asking. Since you´re relatively new to Umbraco I thik that you shold take a look at this:
If you like video tutorials I will recommend you to see this free videos: http://umbraco.tv/videos/umbraco-v7/implementor/Althoughthesearefor Umbraco7,ismost ofthebasicprinciplesin Umbaco,which also actsin thepreviousversioer.except the Razorpath that will need (Umbraco 4.7 or later if I remember correctly).
Thank you so much for your step by step instructions, i had the parameter already added to my document type so creating the seperate macro and inserting it into the template worked perfectly! Thanks again for all your help.
Checking field string length?
Hi, this seems extremely simple but a Google search shows me about 20 different and varied examples which i can't get any to work. I am just trying to check a parameter for my text pages, if the value exists then add some javascript code to redirect the user. Here is my example code:
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:if test="string-length($currentPage/externalRedirect)!=0">
<script language="javascript">
document.location.replace("<umbraco:Item field="externalRedirect" runat="server"></umbraco:Item>");
</script>
</xsl:if>
</xsl:template>
the IF TEST always executes as TRUE so no matter what, it adds the redirect code even when there is no value and that just puts the page in a loop. Please someone help me i have been programming for decades but i am new to XSLT and this is embarassing that i can't get something this easy to work. Please help.
Thanks,
Hi Adrian,
This should work for you. Remember that when you write the URL you will redirect to in the Umbraco field you need to remeber the http://, so like should be like e.g http://www.google.com
/Dennis
Hmm okay thanks for the reply Dennis, it looks like i am missing some fundamental information here because when i add the code to my Textpage template it shows the code in my HTML source and doesn't execute the code. Is it even possible to add XSLT code to a template or should i be using Razor? Sorry for the questions i am very new to this and I appreciate your help.
You can see my example where the XSLT is displayed in html soruce code here: http://jessesjourney.com/who-we-are/brochure.aspx
Hi Adrian,
Okay I will try to guide you step by step so we are get it work for you.
1. Add the field on the document type for e.g frontpage. Go the setting section --> Document type (I have made a screenshot)
2. Then we need to create a XSLT file. Go to developer section, then right click on the XSLT folder. Give the file a name (e.g Redirect) and choose clean. There are some build in templates for e.g navigation and so on. When you create the file don´´t remove the tick in Create Macro.
When you have created the XSLT plaste in this code, and then save the file:
3. Go back to the settings section choose the templates forlder and choose the template where you what the redirect. It could be on the frontpage. (In my example I have choosen the frontpage)
Then click at the button or the click at the arrow that i have marked. When you done that you chould get at list of your macros, could be XSLT or Razor. There you need to find the macro with the name you gave your XSLT when you created it.
When click okay and save the template. After that this should be added in your template.
4. Now go to content page and choose a page with the field where you can add the URL. In my example I added the field to the frontpage, and now I write the URL that the page should redirect to. (See sreenshot)
I hope these screenshot will make it easier to you to get the redirect working.If you have any question about this keep asking. Since you´re relatively new to Umbraco I thik that you shold take a look at this:
http://our.umbraco.org/wiki/reference/xslt
http://our.umbraco.org/documentation/Reference/Templating/managing-templates
If you like video tutorials I will recommend you to see this free videos: http://umbraco.tv/videos/umbraco-v7/implementor/ Although these are for Umbraco 7, is most of the basic principles in Umbaco, which also acts in the previous versioer. except the Razor path that will need (Umbraco 4.7 or later if I remember correctly).
Here is some video tutorials about XSLT, but this need that you subscribe to the Umbraco.tv. http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/xslt-in-umbraco-45.aspx
I hope this helps you, and make sense.
/Dennis
Hi Dennis,
Thank you so much for your step by step instructions, i had the parameter already added to my document type so creating the seperate macro and inserting it into the template worked perfectly! Thanks again for all your help.
Hi Adrian,
Great you got it working.
/Dennis
is working on a reply...