I know this is a very basic question, and in fact this code is based on another topic that I saw earlier. But for the life of me, I can't get this to work.
Please could someone check this code to see if there's a glaring error in it that I've been looking at for too long...
Be sure that you have the parameter set up in the MACRO as well, and watch that you've got the case of the alias the same. So...
Go to the Developer section of umbraco and expand the MACRO tree. Select your CMCCreateImageTag macro. Click on the PARAMETERS tag. Check that you've got a macro parameter with an alias of imgAlias and a type of text (I assume you're passing in a string but if not select the proper data type for the macro parameter). Save the macro.
That should do it.
For debugging, you could add the following at the top of your template to display all that is sent in to your xslt...
<xsl:template match="/"> <textarea> <xsl:copy-of select="/macro" /> </textarea> <!-- the rest of your template goes here -->
One further note... it doesn't matter if you get the xsl:param before the <template match="/"> or inside it. The difference is simply one of scoping... it is a global parameter if outside the template and local to the template if inside. In your example it wouldn't matter since you've only got one <template> anyway.
As simple as that! That's perfect, Doug, thanks a million.
I was attempting to view the /macro xml but obviously nothing was coming through as I had no parameters set up. Somehow I thought that was done behind the scenes, but looking at the parameters now I see it's more powerful than I though.
Passing variables into XSLT macros
Hi all,
I know this is a very basic question, and in fact this code is based on another topic that I saw earlier. But for the life of me, I can't get this to work.
Please could someone check this code to see if there's a glaring error in it that I've been looking at for too long...
The test
<xsl:if test="$imgAlias != ''">
always is empty... (I've also tried using <xsl:param name="imgAlias" select="/macro/imgAlias"/> to no avail)
The calling code is
Put the param for the macro outside of the template:
And check for typos. Do you have the right aliases etc.
hth, Thomas
Hi Thomas, and thanks for the reply.
I have moved the param to where you indicated, with no luck...
If I hardcode the imgAlias name I get the image displayed
So I'm at a loss as to why the parameter is not passed into the macro.
Is there a way to output the macro XML so that I can check if it's being passed in at all?
Thanks again,
Sean
Be sure that you have the parameter set up in the MACRO as well, and watch that you've got the case of the alias the same. So...
Go to the Developer section of umbraco and expand the MACRO tree. Select your CMCCreateImageTag macro. Click on the PARAMETERS tag. Check that you've got a macro parameter with an alias of imgAlias and a type of text (I assume you're passing in a string but if not select the proper data type for the macro parameter). Save the macro.
That should do it.
For debugging, you could add the following at the top of your template to display all that is sent in to your xslt...
One further note... it doesn't matter if you get the xsl:param before the <template match="/"> or inside it. The difference is simply one of scoping... it is a global parameter if outside the template and local to the template if inside. In your example it wouldn't matter since you've only got one <template> anyway.
Let us know what you find out.
cheers,
doug.
As simple as that! That's perfect, Doug, thanks a million.
I was attempting to view the /macro xml but obviously nothing was coming through as I had no parameters set up. Somehow I thought that was done behind the scenes, but looking at the parameters now I see it's more powerful than I though.
Cheers,
Sean
Hello Doug!
I have this pieces of code in my xslt:
<xsl:param name="dClass" select="/macro/cssClass"/>
<xsl:value-of select="concat('<div class="', $dClass,'"', ' style="background-image:url(', $pic, ');background-size: cover;
-moz-background-size: cover;-webkit-background-size: cover;-o-background-size: cover;">')" disable-output-escaping="yes"/>
There is a parameter with aliase "cssClass" in my macro. But the control is visualised like this:
<div class="" style="background-image:url(/media/5606/ygradient.jpg);background-size: cover;
-moz-background-size: cover;-webkit-background-size: cover;-o-background-size: cover;">
The class="" - there is no parameter value passed. I add this to debug:
<textarea>
<xsl:value-of select="$dClass"/>
</textarea>
and there is really no value. Can you help with this?
Regards,
Aleksandar.
Hi Aleksander
Could you show us the code from where you insert the macro in your template?
/Kim A
Hello!
Here is the code:
Regards,
Aleksandar
Hi Aleksander.
I was thinking of the code where you are inserting the macro. The code from your template that looks something like this:
<umbraco:Macro ... ... >
/Kim A
Ooo, sorry! Here it is:
Hmm...okay.
Could you try removing the first slash from the dClass variable like this:
/Kim A
Already did - nothing changes.
Aleksander
And you have declared the parameter on the macro inside Umbraco right? On the macro in the developer section.
/Kim A
Yes, it was a working macro. I just raplaced some hard-cored text with the varriable mentioned above.
Okay, that is very weird. Could you maybe try with another macro parameter? Just a test param, that you'll delete after testing.
/Kim A
Aleksander.
Ik had the same issue. It looked like it had something to do with the name cssClass. I changed it to something else and then it worked.
Hello!
Yes, thanks to Kim, I already decide the problem by changing the name.
Thanks,
Aleksandar
is working on a reply...