I have pages which display a header image when there is an image in the field (imgAlias) which I choose via media picker. However, one of the pages has sub pages, on these I just want to use the same header image as the parent page.
ie test if image is present, if so, use that, if not (I mean the field imgAlias not at all in the document type, not just no image picked - so Im guessing that's 'null' rather than 'empty'), then use parent page image
I have seen that you can you choose, and otherwise xsl commands, however, my slow learning curve continues and I am stuck on what appears to be something quite simple :( please help if anyone can, thanks :)
If value is not an empty string, than just use the code as you've specified already, otherwise get parent node of $currentPage using
$currentPage/parent::node
"ie test if image is present, if so, use that, if not (I mean the field imgAlias not at all in the document type, not just no image picked - so Im guessing that's 'null' rather than 'empty'), then use parent page image"
--> no need for a check on null, it's implicitely done by the first statement
Sorry Dirk, could you just help me out with one more thing? Could I also clarify that this maco runs in the master template and appears in the header on ALL pages. So I cant make two macros, and two templates, and put one macro in each of the two (which would work but not what I want to achieve).
This code displays the correct header (worked on the upper level pages): (xlst error on sub pages)
How do I join these to together into one piece of code? I want it to state if theres a header image, display it, otherwise display the parent image (as it does in second bit of code).
Can't see what I'm doing wrong, want to display a parent image (with alias imgAlias) if the current page has no alias (not if it's empty, just if it's not there at all in the doctype). Anyone see where I'm going wrong? Thanks if you can help :)
the variable $currentPage should never "get" out of scope, so how did you define this var in your xslt. Here's an example of how it should be included in your xslt (I've just created a new xslt (clean template):
Thanks for your patience Dirk, this is my first xlst, but finally,
success! I had forgot to add the alias into the parameter tab in the macro and was using an incorrect alias for the image... doh! This is the whole thing in case any else has the same situation
:)
If field doesn't exist , use parent field
Hi everyone,
So far I have this code here (using umbraco 4.0.4.2)
<xsl:if test="$imgAlias != ''">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
</xsl:attribute>
</img>
</xsl:if>
I have pages which display a header image when there is an image in the field (imgAlias) which I choose via media picker. However, one of the pages has sub pages, on these I just want to use the same header image as the parent page.
ie test if image is present, if so, use that, if not (I mean the field imgAlias not at all in the document type, not just no image picked - so Im guessing that's 'null' rather than 'empty'), then use parent page image
I have seen that you can you choose, and otherwise xsl commands, however, my slow learning curve continues and I am stuck on what appears to be something quite simple :( please help if anyone can, thanks :)
Sam.
Perform a check first whether there's a property with alias = 'imgAlias' and whether that property has a value using the single statement
If value is not an empty string, than just use the code as you've specified already, otherwise get parent node of $currentPage using
"ie test if image is present, if so, use that, if not (I mean the field imgAlias not at all in the document type, not just no image picked - so Im guessing that's 'null' rather than 'empty'), then use parent page image"
--> no need for a check on null, it's implicitely done by the first statement
Hope this helps.
Regards,
/Dirk
Sorry Dirk, could you just help me out with one more thing? Could I also clarify that this maco runs in the master template and appears in the header on ALL pages. So I cant make two macros, and two templates, and put one macro in each of the two (which would work but not what I want to achieve).
This code displays the correct header (worked on the upper level pages): (xlst error on sub pages)
<xsl:if test="$imgAlias != ''">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
</xsl:attribute>
</img>
</xsl:if>
the folowing displays the correct parent header (worked on the sub pages): (xlst error on upper level pages)
<xsl:if test="$imgAlias != ''">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/parent::node/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
</xsl:attribute>
</img>
</xsl:if>
How do I join these to together into one piece of code? I want it to state if theres a header image, display it, otherwise display the parent image (as it does in second bit of code).
Thanks,
Sam.
Tried this but no joy :(
Can't see what I'm doing wrong, want to display a parent image (with alias imgAlias) if the current page has no alias (not if it's empty, just if it's not there at all in the doctype). Anyone see where I'm going wrong? Thanks if you can help :)
Sam.
Hmmmmmm, seemed to be getting a bit closer but getting currentpage not defined or out of scope now...
Can anyone help?? Thanks,
Sam.
the variable $currentPage should never "get" out of scope, so how did you define this var in your xslt. Here's an example of how it should be included in your xslt (I've just created a new xslt (clean template):
Hope this helps.
Regards,
/Dirk
Thanks for your patience Dirk, this is my first xlst, but finally, success! I had forgot to add the alias into the parameter tab in the macro and was using an incorrect alias for the image... doh! This is the whole thing in case any else has the same situation :)
Thanks again Dirk :)
Best regards,
Sam.
Glad I could help, it requires some trial and error sometimes, but once you get the grips... Anyway, good luck on your journey.
Cheers,
/Dirk
Thanks, all the best.
Sam.
Here is a variation on your script, that walks all the way up to content tree untill it finds an image defined for the header:
And here is the same with an added check if any exists at all and a fallback image
Thanks Rik,
Totally works a charm :)
Sam.
is working on a reply...