Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    May 29, 2010 @ 13:21
    MartinB
    0

    Fecth content from one page and display it on another.

    Hi.

    I have a multi-section site (portal like site) and i have around 3 pages with contact and employee and the likes that i'll need repeated in the different sections.

    Is there any way to make one page fetch the content from another and show that content on it self. (mirror like function).

    Thanks in advance.

    /Martin

  • MartinB 411 posts 512 karma points
    May 29, 2010 @ 13:25
    MartinB
    0

    Of course, one could always use umbracoRedirect, but then i'll switch section and i don't want that to happen.

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    May 29, 2010 @ 23:19
    Matt Brailsford
    0

    One way could be to pull out the shared content out of the pages and into a seperate "folder" outside the main structure of the site (ie it's not meant to be navigated to directly) and then have a content picker (or multi content picker) on the pages to point to items to pull into specific regions. Then just have a macro that drops in and knows how to render them?

    Matt

  • MartinB 411 posts 512 karma points
    May 29, 2010 @ 23:50
    MartinB
    0

    Hi Matt

    Well that sounds really awesome. Only one problem..... I'm such a newbie in the world of umbraco and xslt's.

    Might there be a more simple solution, like a contentPicker propery that works together with a macro to fecth the content from a page and show it on another?

    The old CMS i worked with had this "mirror" feature and it was really nice to avoid redundant labour for similar pages that way ^^

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    May 30, 2010 @ 00:40
    Matt Brailsford
    0

    You could do that no problem, the only negative with doing it that way is that you would need to create vert specific macros for each document type you want to mirror. The way I suggested origionaly, would allow you to break it down into smaller parts, therfore make it more reusable, so for example, rather than mirroring a page which has a rich text are, a list of news articles and a movie, if you broke it down into smaller chucks, such as "Rich Text Zone Content", "News List Zone Content" and "Movie Zone Content" and then in your document type define a series of zones, you can than just have a "Zone" macro, that knows how to render each type of "Zone Content" you select.

    In effect, your document types just define reusable content "Zones", and point to reusable "Zone Content" items located elswhere. This also makes it easier to manage, as you don't have to track down which page is the master page, as you know they all just pull the content from the central folder.

    I hope this explains it well enough. If you choose to go this route, just post any questions and I'd be happy to help.

    Matt

  • MartinB 411 posts 512 karma points
    May 30, 2010 @ 01:03
    MartinB
    0

    Hi Matt

    Thank you very much for your time and effort.

    Actually, my pages are very simple! So basically i just need the content from the richText editor on some of the pages. Nothing fancy.

    I already added a "fetchContent" property and so forth, but clearly i lack a xslt that'll make the macro work (i think) :/

  • MartinB 411 posts 512 karma points
    May 30, 2010 @ 21:53
    MartinB
    0

    Hmm. I look at GetItem a little, could that be used to fect the bodyText content from a node through the contentPicker datatype?

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    May 31, 2010 @ 17:46
    Matt Brailsford
    0

    Ooooh, didn't know about GetItem, nice find. It does indeed look like what you are after. You should just be able to wrap it up into an if statement like so:

    <xsl:choose>
      <xsl:when test="string-length($currentPage/data[@alias='fetchContent']) &gt; 0">
        <xsl:value-of select="umbraco.library:GetItem($currentPage/data[@alias='fetchContent'], 'mainContent')" disable-output-escaping="yes" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$currentPage/data[@alias='mainContent']" disable-output-escaping="yes" />
      </xsl:otherwise>
    </xsl:choose>

    Basicaly, if your fetchContent property has a value, then use the value of the property mainContent from that page, otherwise use the property value from the current page.

    Many thanks

    Matt

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 18:07
    MartinB
    0

    Hi Matt

    How do i get mainContent to be the bodyText property from the page i'm pulling the html from?

    I know it might be a very stupid question, i'm just not used to xslts

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    May 31, 2010 @ 18:23
    Matt Brailsford
    0

    Just changing the 2 references of mainContent to be bodyText should do it.

    Many thanks

    Matt

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 19:54
    MartinB
    0

    Haha, actually i realized that just as i pressed "Submit".

    I'll give it a go in af few minutes.

    Thank you :-)

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 20:20
    MartinB
    0

    Ok i'm getting a strange output.

    This is what i did:

    · make xlst file with code above and make the macro at the same time.

    · add Fetch Content property with alias FetchContent to my textpage template and chose "contentPicker" as type.

    · Went to a random page, running on textpage template, chose Properties and selected the page i wanted to fecth content from through the content picker

    · all i get is: "<Macro: (,)>"

    Am i not doing this the right way or?

    Your help is much appreciated!

    ·

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 20:21
    MartinB
    0

    xslt:

    <?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"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:choose>
    <xsl:when test="string-length($currentPage/data[@alias='fetchContent']) &gt; 0">
    <xsl:value-of select="umbraco.library:GetItem($currentPage/data[@alias='fetchContent'], 'bodyText')" disable-output-escaping="yes" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$currentPage/data[@alias='bodyText']" disable-output-escaping="yes" />
    </xsl:otherwise>
    </xsl:choose>

    </xsl:template>

    </xsl:stylesheet>

    ·

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 20:25
    MartinB
    0

    Oh, actually the output that i got came from the macro as i tried to put it onto the textpage template.

    So i really get nothing from the contentpicker property

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 20:51
    MartinB
    0

    Ok, now i got a little further:

    It seems that the above just picks the content of the same page that i am on, instead of the one i select through the FetchContent property.

    At the same time i have to add the macro to the template and since i have 3 or more different pages that i need to repeat around the website, i have to make a xslt and macro for each of these. I would like something more versatile if possible.

    1 xslt and 1 macro for all pages where i need to use the FetchContent property.

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    May 31, 2010 @ 20:56
    Matt Brailsford
    0

    Ok, first thing I would say is that alias' are case sensitive, so might not be pulling content through if your alias on the doc is "FetchContent" as in the XSLT it is referenced as "fetchContent"

    Re a more versatile solution, if the properties and datatypes are the same, you can just reuse the same macro, or you could make the macro configurable (ie pass in the name of the field you want to mirror).

    I'd say get the first bit working and then come back with any questions you have about making it more flexible.

    Matt

  • MartinB 411 posts 512 karma points
    May 31, 2010 @ 21:16
    MartinB
    0

    Hi Matt

    I don't know what i did wrong! I noticed the different aliases earlier and corrected them. Well... i just made it all from scratch and now it works (also as versatile as i need!)!

    Thank you very much for your patience, you're a star!

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    May 31, 2010 @ 22:38
    Matt Brailsford
    0

    No problem.

    Glad you got it up and running.

    Matt

  • arviman 71 posts 92 karma points
    Jun 02, 2010 @ 01:51
    arviman
    0

    Good to hear you got it solved, but IMHO you could have created a macro that returns the commonly needed items and simply called that macro in all 3 pages. In the macro, you could use the hard-coded id of the node that contains the properties you needed, and displayed them similar to what you used in the xslt.

    <xsl:for-each select="umbraco.library:GetXmlNodeById(<some id>)">
    <xsl:value-of select="./data [@alias='bodyText']/text()"/>
    </xsl:for-each>

Please Sign in or register to post replies

Write your reply to:

Draft