In my master template, I want to have a hyperlink that a user can edit via Umbraco. I added a property to my master document type of Content Picker. I've tried many ways to add the content picker link to my master template including XSLT and I either get blank results or errors.
How do I code this while also ensuring that all pages that inherit from my master document type display the link?
I am using 4.5 and was using the old format. Using $currentPage/myLinkProperty and it seems to work fine. Now, I cannot get the node name. Using <xsl:value-of select="@nodeName"/> in place of Click Me causes nothing to display.
Awesome, another step closer. Now, all I need is to make it recursive so every page based upon that document type defaults to the value set in the master doc type.
Ok, I think I have my final solution so I thought I would share. I ran into another issue... I wanted the property from the currentPage to take priority. I only wanted to go the the ancestor property if the currentPage property is empty. With ancestor-or-self you cannot control that. So I check for currentPage first.
If you prefer your existing solution I think you can get the recursion behaving like you want by adding position() = 1 to the Xpath conditions, according to this post anyway
Yes! Now I know how to pass in values to a macro, which will be helpful for some other tasks. Below is my final XSLT code which is much simpler and cleaner than what I had before. One thing, why do I always have to check for an empty value? Does that just satisfy the editor?
Checking the string length is good practise, and prevents the value from being used if it is empty, which could cause an XSLT template error otherwise.
I have created a Master template which displays a text string and related links using XSLT/Macro(Using Umbraco 4.5).When I try to access it from my child page,it displays the textstring but does not display anything for relatedlinks.Can anyone help me with this?
Display Content Picker link in master template
In my master template, I want to have a hyperlink that a user can edit via Umbraco. I added a property to my master document type of Content Picker. I've tried many ways to add the content picker link to my master template including XSLT and I either get blank results or errors.
How do I code this while also ensuring that all pages that inherit from my master document type display the link?
Something like this should work, in an XSLT macro:
Or if you're using 4.5, it would be $currentPage/myLinkProperty instead
I am using 4.5 and was using the old format. Using $currentPage/myLinkProperty and it seems to work fine. Now, I cannot get the node name. Using <xsl:value-of select="@nodeName"/> in place of Click Me causes nothing to display.
Try <xsl:value-of select="$currentPage/@nodeName"/> :)
That give me the node name of the current page instead of the node name of the targeted page.
Oh, sorry, wasn't thinking. To get properties from the targeted page you can use GetXmlNodeById:
Awesome, another step closer. Now, all I need is to make it recursive so every page based upon that document type defaults to the value set in the master doc type.
This *should* get the value recursively:
Make sure to update this Xpath statement in your IF, href attribute and inside the NiceUrl function
Ok, I think I have my final solution so I thought I would share. I ran into another issue... I wanted the property from the currentPage to take priority. I only wanted to go the the ancestor property if the currentPage property is empty. With ancestor-or-self you cannot control that. So I check for currentPage first.
Hi Connie
Why not just use a recursive macro property?
Just define a property on your macro, then set it's value when you embed it like so
Umbraco will automaticaly check the current page, then it's ancestors untill it finds a value, and then pass it into your macro.
Matt
UPDATE (The example got stripped from my phone)
Ah, forgot all about that.
If you prefer your existing solution I think you can get the recursion behaving like you want by adding position() = 1 to the Xpath conditions, according to this post anyway
Matt's solution may be easier though :)
-Tom
Matt,
Ok, so if I understand, the idea is to pass a property from the page to the macro and then use that value in my macro? I sort of get it...
Hi Connie,
Thats correct yes. Define the property on your doc type(s), then in your template, pass the value to your macro like so
Then you can retreive the value from within the macro like so
(Notice the /macro/ at the begining. I'm not sure if this has changed in 4.5 thought)
Matt
Yes! Now I know how to pass in values to a macro, which will be helpful for some other tasks. Below is my final XSLT code which is much simpler and cleaner than what I had before. One thing, why do I always have to check for an empty value? Does that just satisfy the editor?
Hi Connie,
Checking the string length is good practise, and prevents the value from being used if it is empty, which could cause an XSLT template error otherwise.
Matt
Hi,
I have created a Master template which displays a text string and related links using XSLT/Macro(Using Umbraco 4.5).When I try to access it from my child page,it displays the textstring but does not display anything for relatedlinks.Can anyone help me with this?
Thanks,
Brady
is working on a reply...