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).
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?
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 ^^
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.
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:
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.
· 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
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.
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.
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!
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.
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
Of course, one could always use umbracoRedirect, but then i'll switch section and i don't want that to happen.
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
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 ^^
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
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) :/
Hmm. I look at GetItem a little, could that be used to fect the bodyText content from a node through the contentPicker datatype?
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:
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
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
Just changing the 2 references of mainContent to be bodyText should do it.
Many thanks
Matt
Haha, actually i realized that just as i pressed "Submit".
I'll give it a go in af few minutes.
Thank you :-)
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!
·
xslt:
·
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
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.
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
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!
No problem.
Glad you got it up and running.
Matt
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>
is working on a reply...