Hi. I've tried for too long now to let a couple of simple script tags come through to the html out put and need an advice.
I can manage to let it out by adding the html to the masterpage template and then it works, but every other try else seems hard. What I want is to have the option of a unique script for every page I create....
I've read about a similar problem with youtupe inline scripts, where the solution is to create an xslt file and a connecting macro.
var path ="]]><xsl:value-of select="$videopath" /><![CDATA["; var videowidth ="]]><xsl:value-of select="$videowidth" /><![CDATA["; var videoheight ="]]><xsl:value-of select="$videoheight" /><![CDATA["; var flashvars ={}; var attributes ={}; var params ={ wmode:"transparent", allowfullscreen:"true", allscriptaccess:"always" };
This is just to help understand why your XSLT isn't working the way you think it should.
XSLT is basically just an XML document, and in XML you write a comment just like you would in HTML. So effectively, you've commented that section of your XSLT out and hidden it from the processor, which is why your output only contains the script tags.
What you really want to do is to generate a comment in the output, which is done with the <xsl:comment> instruction:
<!-- Hey, I'm a comment in the code -->
<xsl:comment>Hey, I will be a generated comment</xsl:comment>
- I put the variables inside the template so it's possible to call the template with overriding parameters, e.g., to override the width & height but keep the client & slot:
+1 one for Dan's soultion, which I would at any time consider the most simple and elegant. The other way of doing it seems to cumbersome and confusing. But of course you can have a reason for choosing to do it that way. But maybe you should consider simplyfying it for your own benefit?
<script> in umbraco pages
Hi.
I've tried for too long now to let a couple of simple script tags come through to the html out put and need an advice.
I can manage to let it out by adding the html to the masterpage template and then it works, but every other try else seems hard.
What I want is to have the option of a unique script for every page I create....
I've read about a similar problem with youtupe inline scripts, where the solution is to create an xslt file and a connecting macro.
this is somewhat I want to add to the pages:
but with this
My xslt first try:
plus 4 macros with
type text and names and aliases:
"_ad_client"
"_ad_slot"
"_ad_width"
"_ad_height"
then this is what it html outputs:
Is xslt the way to solve this?
why isn't the solution a simple macro, where the data of a textfield in one parameter is just printet raw?
Thanks in advance and best regards.
Soren.
You need to use cdata for your scripts
Here's an example from a macro of mine
This shows the CDATA, and how to access xslt "variables" inside js
Dan
Hi Søren,
This is just to help understand why your XSLT isn't working the way you think it should.
XSLT is basically just an XML document, and in XML you write a comment just like you would in HTML. So effectively, you've commented that section of your XSLT out and hidden it from the processor, which is why your output only contains the script tags.
What you really want to do is to generate a comment in the output, which is done with the <xsl:comment> instruction:
So you'd do something like this instead:
- I put the variables inside the template so it's possible to call the template with overriding parameters, e.g., to override the width & height but keep the client & slot:
/Chriztian
Works great.
Thanks a lot, I appreciate it.
+1 one for Dan's soultion, which I would at any time consider the most simple and elegant. The other way of doing it seems to cumbersome and confusing. But of course you can have a reason for choosing to do it that way. But maybe you should consider simplyfying it for your own benefit?
/Jan
is working on a reply...