But even though my address bar states someting like http://mydomain.com/myPage.aspx?area=MyArea the macro seems to receive an empty parameter and diaplsying the parameter in the page renders an empty string.
you ain't missing anything, syntax is correct and should reproduce exactly that result. Meanwhile, if you're still stuck on this, fetch the querystring var in code (either xslt through umbraco.library:RequestQuerystring('key') or through c# code)
Thank you, Dirk. Doing it in the XSL feels tricky as I actually need the macro itself to work with the parameter being set both both statically and from the query string. I'm an old time classic ASP hacker, any hints on how I would do it in C#? I tried
Yeah, mixing quotes and double quotes can get messy, and won't work indeed. Anyway, if you need it work both ways, still can do the same trick. Check in xslt whether a value is passed (if it's set statically) and if so, you're done and use that value. If no value is passed, ie. empty string, check for the querystring var? Does that make sense?
Finally made it work. Did as you said but the other way around, tested if the request param existed and if not assumed a static param could be used. this was because I could not find a way to compare the static param with an empty string - comparing it with '' always returned false. I could however test the request param for existance. See code example below.
Is it that you want to test first if coming in on query string, if not then use macro parameter? I would use a <xsl:choose> in this scenario, but it may not meet your needs. Hard to tell from the info provided if you want one to override the other.
Well, the base problem was that I can't make [@queryParam] work. That aside I can't seem to test (with neither xsl:choose nor xsl:if) if a given param is equal to the empty string (''). Both <xsl:if test="$area"> and <xsl:if test="$area = ''"> as well as the equivalents using xsl:choose returned true whatever I value I gave the parameter. I solved it by instead first creating a local var (<xsl:variable name="reqArea" select="umbraco.library:RequestQueryString('area')"/>) and then doing <xsl:choose test="@reqArea">. That returns true only if I have set the parameter in the query.
I'm confused about not being able to test if a given (static) param is empty or not.
The reason you're test is returning true is because if the [area] parameter is not populated at the time the macro is called, then the literal '[area]' string is passed in. If you run an xsl:choose, always test the querystring first, then if it is empty, you could have another xsl:when that tests that $area is != '[area'] and $area is != ''.
The reason your test is returning true is because if the [area] parameter is not populated at the time the macro is called, then the literal '[area]' string is passed in. If you run an xsl:choose, always test the querystring first, then if it is empty, you could have another xsl:when that tests that $area is != '[area'] and $area is != ''.
How to make bracket syntax work
I have a macro with one parameter. Calling that macro with a static value works just fine, like:
But I want to call the macro with a dynamic parameter, picked from my query string, and thought "bracket syntax" would do the trick:
But even though my address bar states someting like http://mydomain.com/myPage.aspx?area=MyArea the macro seems to receive an empty parameter and diaplsying the parameter in the page renders an empty string.
What am I missing?
/Jonas
you ain't missing anything, syntax is correct and should reproduce exactly that result. Meanwhile, if you're still stuck on this, fetch the querystring var in code (either xslt through umbraco.library:RequestQuerystring('key') or through c# code)
Cheers,
/Dirk
Thank you, Dirk. Doing it in the XSL feels tricky as I actually need the macro itself to work with the parameter being set both both statically and from the query string. I'm an old time classic ASP hacker, any hints on how I would do it in C#? I tried
but that did not work (and I didn't expect it to).
From (the very little) I know about ASP.NET I would create a code-behind file, but that is not what I should do when running Umbraco, is it?
/Jonas
Oh, and I guess I should mention that I run Umbraco version 4.5.1, if that matters.
/Jonas
Jonas,
Yeah, mixing quotes and double quotes can get messy, and won't work indeed. Anyway, if you need it work both ways, still can do the same trick. Check in xslt whether a value is passed (if it's set statically) and if so, you're done and use that value. If no value is passed, ie. empty string, check for the querystring var? Does that make sense?
And, no, version doesn't matter in this case :D
Cheers,
/Dirk
Finally made it work. Did as you said but the other way around, tested if the request param existed and if not assumed a static param could be used. this was because I could not find a way to compare the static param with an empty string - comparing it with '' always returned false. I could however test the request param for existance. See code example below.
First assigned to local vars:
<xsl:variable name="reqArea" select="umbraco.library:RequestQueryString('area')"/>
<xsl:variable name="area" select="/macro/area"/>
Then tried these different versions:
<xsl:if test="$reqArea"> <!-- Works fine -->
<xsl:if test="$area"> <!-- No good - always returns true even if no parameter is set-->
<xsl:if test="$area = ''"> <!-- No good - always returns true even if no parameter is set-->
If anyone knows what I'm doing wrong it would be interesting to know. But in terms of the original question the problem is solved.
Thanks for all help!
Is it that you want to test first if coming in on query string, if not then use macro parameter? I would use a <xsl:choose> in this scenario, but it may not meet your needs. Hard to tell from the info provided if you want one to override the other.
Don
Well, the base problem was that I can't make [@queryParam] work. That aside I can't seem to test (with neither xsl:choose nor xsl:if) if a given param is equal to the empty string (''). Both <xsl:if test="$area"> and <xsl:if test="$area = ''"> as well as the equivalents using xsl:choose returned true whatever I value I gave the parameter. I solved it by instead first creating a local var (<xsl:variable name="reqArea" select="umbraco.library:RequestQueryString('area')"/>) and then doing <xsl:choose test="@reqArea">. That returns true only if I have set the parameter in the query.
I'm confused about not being able to test if a given (static) param is empty or not.
/Jonas
Hey Jonas,
The reason you're test is returning true is because if the [area] parameter is not populated at the time the macro is called, then the literal '[area]' string is passed in. If you run an xsl:choose, always test the querystring first, then if it is empty, you could have another xsl:when that tests that $area is != '[area'] and $area is != ''.
This will definitely solve your issue.
Don
Hey Jonas,
The reason your test is returning true is because if the [area] parameter is not populated at the time the macro is called, then the literal '[area]' string is passed in. If you run an xsl:choose, always test the querystring first, then if it is empty, you could have another xsl:when that tests that $area is != '[area'] and $area is != ''.
This will definitely solve your issue.
Don
Aha, that was very interesting! As mentioned earlier I've solved the problem pretty much like that, but this is very good to know for future needs.
Just curious, I guess there is some kind of typo in you post. You wrote
$area is != '[area'] and $area is != ''
The single quoutes on the first expression is wrong, I guess. Should it be
$area is != '[area]' and $area is != ''
or
$area is != ['area'] and $area is != ''
I suspect that the first version is the correct one, right?
/Jonas
is working on a reply...