Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Trine 29 posts 89 karma points
    Jul 17, 2013 @ 22:22
    Trine
    0

    Display properties through content picker

    Hi.

    I’m looking for a way to display one piece of Umbraco content across multiple pieces of Umbraco content in Umbraco 4.9.

    I’ve created a doc type called related link with 3 custom properties: h2 (textstring), body copy (richtext editor) and image (media picker). Using this doc type I want to create a piece of content I can place into multiple site pages from a single source so ongoing management of the content becomes easier.

    Is this possible within Umbraco?

    I’ve used the content picker to display the nodename of the related link content within a target page, but I can’t display the properties of the related link content within the target page.

    The XSLT I’m using to get the nodename is: 

     

    <xsl:template match="/"

               <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/data[@alias='relatedLinkText'])/@nodeName"/>           </xsl:template>

    I’ve had a look at razor macros and the ultimate picker but haven’t got anywhere as I’m not really a developer. It’s pretty critical to the site so I’m really hoping someone can help.

    Thanks,

     

    Chris

  • Sebastian Dammark 583 posts 1407 karma points
    Jul 18, 2013 @ 01:04
    Sebastian Dammark
    0

    Hi

    What version of Umbraco are you running and can you post the XML as well ?

  • Trine 29 posts 89 karma points
    Jul 18, 2013 @ 19:45
    Trine
    0

    Hi Sebastian,

     

    I'm using v4.9.0.

     

    The XSLT I've got is:

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>

        <xsl:stylesheet

        version="1.0"

        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

        xmlns:msxml="urn:schemas-microsoft-com:xslt"

        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:twitter.library="urn:twitter.library" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" xmlns:google.maps="urn:google.maps"

        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets twitter.library PS.XSLTsearch google.maps ">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

        <xsl:template match="/">

            <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/relatedContent2)/@nodeName"/>

        </xsl:template>

        </xsl:stylesheet>

     

    and on the template the macro shows as:

     

        <umbraco:Macro Alias="RelatedContent2" runat="server"></umbraco:Macro>

     

    That is showing the node name but none of the content inside the relevant document type. Can you help? 

  • Sebastian Dammark 583 posts 1407 karma points
    Jul 19, 2013 @ 01:06
    Sebastian Dammark
    0

    Hi

    Try this.
    It should return all child nodes to the ID stored in relatedContent2

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml umbraco.library">
    
        <xsl:output method="xml" omit-xml-declaration="yes"/>
        <xsl:param name="currentPage"/>
    
        <xsl:template match="/">
            <xsl:apply-templates select="$currentPage/relatedContent2[normalize-space()]" />
        </xsl:template>
    
        <xsl:template match="relatedContent2">
            <xsl:variable name="data" select="umbraco.library:GetXmlNodeById(.)" />
    
            <xsl:apply-templates select="$data[not(error)]" mode="container" />
        </xsl:template>
    
        <xsl:template match="*" mode="children">
            <li>
                <strong>
                    <xsl:value-of select="concat(name(), ': ')" />
                </strong>
                <xsl:value-of select="text()" disable-output-escaping="yes" />
                <xsl:apply-templates select="child::node()[@isDoc]" mode="container" />
            </li>
        </xsl:template>
    
        <xsl:template match="*" mode="container">
            <h2>
                <xsl:value-of select="concat('DocumentType: ', name())" />
            </h2>
            <ul>
                <xsl:apply-templates select="child::node()" mode="children" />
            </ul>
        </xsl:template>
    
    </xsl:stylesheet>

     

  • Sebastian Dammark 583 posts 1407 karma points
    Jul 19, 2013 @ 01:27
    Sebastian Dammark
    0

    In your original code, you're only asking for the @nodeName and nothing else.

    You could replace

    <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/relatedContent2)/@nodeName"/>

    with

    <xsl:apply-templates select="umbraco.library:GetXmlNodeById($currentPage/relatedContent2)/child::node()" mode="output"/>

    <xsl:template match="*" mode="output">
    <xsl:value-of select="." disable-output-escaping="yes" />
    </xsl:template> 
  • Trine 29 posts 89 karma points
    Jul 20, 2013 @ 14:03
    Trine
    0

    Hi Sebastian,

    Thanks so much for your help. :-)

    I used the first of your two answers and the content I was looking for has been placed into the page along with property aliases and the doc type. It's appearing the the page as below:

    Is there any way to remove the aliases and the doc type info so it's only the content that's renderend to the page? Also, If I apply CSS styling to the original related link doc (eg: positioning the image relative to the text), can this styling be applied to the link properties when they're rendered in the target page? If not it shouldn't be a problem - just curious.

    I also tried your second answer however was given the following error message when I tried to save the XSLT file:
     
    The error code in detail is: 

    Error occured

    Error in XSLT at line 17, char 12
    15:      <xsl:template match="/">
    16:      
    17: >>>  <xsl:apply-templates select="umbraco.library:GetXmlNodeById($currentPage/relatedContent2)/child::node()" mode="output"/><xsl:template match="*" mode="output"><xsl:value-of select="." disable-output-escaping="yes" /></xsl:template> <<<
    18:      
    19: 

    Thanks again for all your help.

  • Sebastian Dammark 583 posts 1407 karma points
    Jul 22, 2013 @ 00:43
    Sebastian Dammark
    0

    Hi

    To remove everything but content, just delete from <strong> to </strong> including the line between.

    I don't know if you can reuse your original styling since I haven't seen your original markup.

    Why you get the error in the 2nd example, puzzles me.  I have no clue :)
    Have you tried to save the XSLT file with "Skip testing (ignore errors)" enabled ?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 22, 2013 @ 08:54
    Chriztian Steinmeier
    101

    Hi Trine/Sebastian,

    The reason for the last error ("Line 17, char 12") is not visible in the screenshot, but I can see from the errormessage what's wrong. The template (<xsl:template>...) that's at the end of that line needs to be moved out to the root level, as <xsl:template> elements can't be nested. So something like this instead:

    <xsl:template match="/">
        <xsl:apply-templates select="umbraco.library:GetXmlNodeById($currentPage/relatedContent2)/node()" mode="output" />
    </xsl:template>
    
    <xsl:template match="*" mode="output">
        <xsl:value-of select="." disable-output-escaping="yes" />
    </xsl:template>

    /Chriztian 

  • Sebastian Dammark 583 posts 1407 karma points
    Jul 23, 2013 @ 17:33
    Sebastian Dammark
    0

    Hi Chriz

    Of course, my dear Watson ... :)

    // Sebastian

  • Trine 29 posts 89 karma points
    Aug 05, 2013 @ 22:08
    Trine
    0

    That worked a treat!!

     

    Thank you very much, both of you!

Please Sign in or register to post replies

Write your reply to:

Draft