Copied to clipboard

Flag this post as spam?

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


  • Dave Brislane 15 posts 46 karma points
    Sep 07, 2010 @ 12:47
    Dave Brislane
    0

    Easiest way to re-use content

    Hi All.

    I am new to Umbraco and really like it so far, however have I hit a problem with finding the easiest way to re-use content.  I have used larger CMS's in the past and the ability to create a page with a block of text and then re-use this text block on other pages is fairly simple, however I am unable to find the best way to do this in Umbraco.  

    I have read some of the posts that have already been posted in relation to this problem, however I have still not be able to successfully re-use content using the methods suggested.  Would anyone be able/willing to provide a simple step by step instruction on the easiest way to do this (I am also new to XSLT so any code examples would be gratefully received also)?

    I am currently building my site using Umbraco 4.0.4.2 as I am also using the Cogworks Flexible Navigation package which isn't currently compliant with the new XML schema in Umbraco 4.5.x.

    Thanks in advance.

    Dave.

  • Aron Gamble 63 posts 76 karma points
    Sep 07, 2010 @ 12:55
    Aron Gamble
    0

    I also needed to re-use a lot of content but unfortunately i couldn't find a graceful way to do it. I was told of a way to do it but it was a bit of a hack so we managed to persuade the client to have pages that linked to the main content instead. 

  • Sascha Wolter 615 posts 1101 karma points
    Sep 10, 2010 @ 01:06
    Sascha Wolter
    0

    Hi Dave,

    we had the same problem e.g. for items in a right hand column that need to be re-used on multiple pages and also need to be selectable by the CMS users. What I ended up doing was the following:

    1. create a section outside of the web site root where the content can sit (it needs to be separate as the content doesn't 'belong' to any one page alone).

    2. create a tree multi picker data type and add it to all pages where CMS users can select items from the pool

    3. give users the ability to create new items in the pool by simply adding new pages of a certain doc type, e.g. an image advertisement with a link (none of these have associated templates)

    4. Now on the template for each of these pages there is one Xslt file which is responsible for generating the ouput. As the node id's of the pool items are stored in the custom data type on each page as comma separated list all you have to do is iterate through the ids, check for the type of the item in a huge choose statement and then display the item based on its type.

    Hope that helps,

    Sascha

  • Dave Brislane 15 posts 46 karma points
    Sep 14, 2010 @ 13:28
    Dave Brislane
    0

    Hi All.

    Many thanks for your replies.  We eventually found a suitable solution for what we were after similar to what you suggested Sascha.

    Thanks again.

    Dave.

  • Thomas Foskey 15 posts 35 karma points
    Dec 20, 2010 @ 02:48
    Thomas Foskey
    0

    Hi Everyone,

    I'm still trying to get this concept of re-using multiple content "blocks" on the same page figured out.  The one element that is still puzzling me is the XSLT.  Can someone kindly post a sample implementation of the actual XSLT that handles the rendering of the content?  I too am new to XSLT and any samples would be very helpful.  I assume the next step is to create a macro based on that XSLT file and then add that macro anywhere you want to render the content blocks in the template.  I have seen multiple instructions on how to do this, but I haven't found any XSLT that works or been able to come up with my own implementation.

    Thanks so much!

  • Sascha Wolter 615 posts 1101 karma points
    Dec 20, 2010 @ 03:23
    Sascha Wolter
    0

    Hi Thomas,

    I'm writing this out of the top of my head, so there might be some minor mistakes in the following.

    Let's assume you have a tree multi picker control somewhere on a node and you've selected with it a number of other content nodes which are not actually pages but placeholders (or data holders) for e.g. right hand content. Let's assume in that particular instance your've selected nodes 1244, 1311 and 1312. In the Xslt you would do something like this to render it:

    ...

    <xsl:for-each select="Exslt.ExsltStrings:split($currentPage/MyRightHandColumnTreePickerProperty, ',')">            //'loops' through the node ids

    <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(current())" />                                    //gets the actual node with the id; perform check!

    <xsl:choose>                                                                                                                                                 //call the template that matches the type of the node

        <xsl:when test="currentNoce:local-name() == 'SmallAdvertisement'">

            <xsl:call-template name="renderSmallAdvertisement">

                <xsl:with-param name="currentNode" select="$currentNode" />

            </xsl:call-template>

        </xsl:when>

        <xsl:when test="currentNoce:local-name() == 'BigAdvertisement'">

            <xsl:call-template name="renderBigAdvertisement">

                <xsl:with-param name="currentNode" select="$currentNode" />

            </xsl:call-template>

        </xsl:when>

        ...

    </xsl:choose>

    </xsl:for-each>

    ...

    <xsl:template name="renderSmallAdvertisement">

        <xsl:param name="currentNode" />

        <div class="smallAdvertisement">Title: <xsl:value-of select="$currentNode/@nodeName" /> </div>              //you have access to all the data of that node

    </xsl:template>

    ...

    I'm sure it can be done in a myriad other ways, however I hope this will lead you on the right track.

    Cheers,

    Sascha

  • Thomas Foskey 15 posts 35 karma points
    Dec 20, 2010 @ 06:10
    Thomas Foskey
    0

    Hi Sascha,

     

    I tried plugging in your sample xslt to see what it would give me (I learn better by seeing it.) and it is complaining on this line:

     

    "<xsl:when test="currentNoce:local-name() == 'BigAdvertisement'">"  saying the prefix "currentNoce" is not defined.  I tried changing it to currentNode and prefacing it with a "$" and it still complained.  I hate to be a pain, but if I can get something working and see what it is doing, it would make more sense to me.

     

    I also installed the tree multi picker package and implemented it.  However when I go to view the tree, it throws this error:

     

    "Method not found: 'System.String umbraco.cms.presentation.Trees.BaseTree.GetTreeServiceUrl(System.Object)'."

     

    Here is what I did to implement the tree multi picker:

     

    1. Created a "Banner Picker" data type with Tree Multi Picker as the render control.

    2. I assigned the Parent nodeid as -1

    3. Created a "Banners" document type and associated the Banner Picker as a property to the "Tree" tab.

    4. Created a new node of the Banners document type which has a nodeid of 1168.

    5. Changed the Banner Picker parent nodeid to 1168 and it still throws the exception.

     

    Am I missing something here, or am I doing something terribly wrong?

  • Thomas Foskey 15 posts 35 karma points
    Dec 20, 2010 @ 06:18
    Thomas Foskey
    0

    Ok, I just found where Tree Multi Picker is not working with version 4.5.2 which just so happens to be the version I'm running.  Just fabulous.  Would anyone happen to have any other examples of how to implement content re-use equipped with a full working xslt implementation?  Basically, I have these "content blocks" that would I would like to drop on any page I need to via a macro.

  • Sascha Wolter 615 posts 1101 karma points
    Dec 20, 2010 @ 06:32
    Sascha Wolter
    0

    Hi Thomas,

    unfortunately I don't have access to the Umbraco installation where I have implemented this last, will try to remember to post you my example after work (3-4 hours), it's using 4.0.4.2 though, which means the old xml schema, so I'm not sure how much that will help you as you can't just paste it in and it works.

    As to the TreeMultiPicker: the one from uComponents works like a charm with 4.5.2, please give that a shot.

    Cheers,

    Sascha

  • Thomas Foskey 15 posts 35 karma points
    Dec 20, 2010 @ 10:53
    Thomas Foskey
    0

    Thank you, Sascha!  Any examples you can provide would be awesome.  I'll give uComponent's version a shot and see that one works.

  • Thomas Foskey 15 posts 35 karma points
    Dec 20, 2010 @ 11:07
    Thomas Foskey
    0

    I've got the multi tree picker working now!  No problems at all with using uComponents. They have a TON of components...that''s awesome!  Now if I can just get the content block functionality working, I'll be in business.

  • Sascha Wolter 615 posts 1101 karma points
    Dec 20, 2010 @ 14:27
    Sascha Wolter
    0

    Hi Thomas,

    here is the example copied directly from a working solution. Just remember it's for 4.0.4.2, so it won't work 'as is' with 4.5.2.

        <xsl:template match="/">

            <xsl:if test="$currentPage/data[@alias='rightColumnAssets'] != ''">
                <xsl:for-each select="Exslt.ExsltStrings:split($currentPage/data[@alias='rightColumnAssets'], ',')">
                    <xsl:variable name="item" select="umbraco.library:GetXmlNodeById(.)" />
                    <div>
                        <xsl:choose>
                            <xsl:when test="$item/@nodeTypeAlias='SingleImageAdvert'">
                                <xsl:call-template name="renderSingleImageAdvert">
                                    <xsl:with-param name="item" select="$item" />
                                </xsl:call-template>
                            </xsl:when>
                            <xsl:when test="$item/@nodeTypeAlias='ExternalLink'">
                                <xsl:call-template name="renderExternalLink">
                                    <xsl:with-param name="item" select="$item" />
                                </xsl:call-template>
                            </xsl:when>
                            <!-- and many more -->
                        </xsl:choose>
                        <xsl:comment />
                    </div>
                </xsl:for-each>
            </xsl:if>

        </xsl:template>

        <xsl:template name="renderSingleImageAdvert">
            <xsl:param name="item"/>

            <a>
                <xsl:attribute name="href">
                    <xsl:choose>
                        <xsl:when test="$item/data[@alias=concat('linkInternal', $langExt)] != ''">
                            <xsl:value-of select="umbraco.library:NiceUrl($item/data[@alias=concat('linkInternal', $langExt)])" />
                        </xsl:when>
                        <xsl:when test="$item/data[@alias=concat('linkExternal', $langExt)] != ''">
                            <xsl:value-of select="$item/data[@alias=concat('linkExternal', $langExt)]" />
                        </xsl:when>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:if test="$item/data[@alias=concat('linkInternal', $langExt)] = ''">
                    <xsl:attribute name="target">
                        _blank
                    </xsl:attribute>
                </xsl:if>
                <xsl:if test="$item/data[@alias=concat('image', $langExt)] != ''">
                    <img src="{umbraco.library:GetMedia($item/data[@alias=concat('image', $langExt)], false)/data[@alias='umbracoFile']}" alt="{$item/data[@alias=concat('altText', $langExt)]}" />
                </xsl:if>
            </a>
        </xsl:template>

        <xsl:template name="renderExternalLink">
            <xsl:param name="item"/>

            <a href="{$item/data[@alias=concat('link', $langExt)]}" target="_blank" class="redArrow">
                <xsl:value-of select="$item/data[@alias=concat('linkText', $langExt)]"/>
            </a>
        </xsl:template>

    Hope that is a bit clearer! :)

  • Thomas Foskey 15 posts 35 karma points
    Dec 22, 2010 @ 05:33
    Thomas Foskey
    0

    It's working now!  In case anyone is trying to do something similar, here is my XSLT:

    <xsl:template match="/">
      <!--Get the Banners Node (1168)-->
    <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(1168)" />
      <xsl:for-each select="$node/availableBanners/MultiNodePicker/nodeId">
        <xsl:variable name="item" select="." /><br/>
        <xsl:value-of select="umbraco.library:GetXmlNodeById($item)/bodyText" disable-output-escaping="yes"/>
    </xsl:for-each>
    </xsl:template>

    All you need to do is plug in the node id of the parent node that contains your nodes in the multi-node tree picker.  I will also be posting a step-by-step "How-To" for implementing content blocks that will be easy to understand for other beginners like myself.

Please Sign in or register to post replies

Write your reply to:

Draft