Blog

How to: Display content in another page

Problem: How do I display content from one page on another?

Solution: Using the Mura tag, I was able to come up with two code blocks that would show the body content.

Using the following block, it's possible to use the filename (url) to grab the body content.

[ mura ]getServiceFactory().getBean('contentManager').getActiveContentByFilename('FILENAME', 'SITEID').getBody()[ /mura ]

This code uses the contentID instead.  The contentID can be found in the advanced tab.

[ mura ]getServiceFactory().getBean('contentManager').getActiveContent('CONTENTID', 'SITEID').getBody()[ /mura ]

So if I wanted to use either method, I would create 2 pages.  One named content source and the other named content display. On the content source page, I would put my content.  Then on the content display page, I would use the Mura tag like so:

[ mura ]getServiceFactory().getBean('contentManager').getActiveContentByFilename('content-source', 'SITEID').getBody()[ /mura ]

or

[ mura ]getServiceFactory().getBean('contentManager').getActiveContent('CONTENTID', 'SITEID').getBody()[ /mura ]

Both methods will return the body content.

Edit: I wasn't clear about the filename.  To use getActiveContentByFilename(), grab the text in the URL after index.cfm/.  For example:

This page's URL is: /index.cfm/blog/test//blog/how-to-display-content-in-a-separate-page/, so I would take blog/how-to-display-content-in-a-separate-page as the filename.  The final function call would be:

[ mura ]getServiceFactory().getBean('contentManager').getActiveContentByFilename('blog/how-to-display-content-in-a-separate-page', 'mura').getBody()[ /mura ]

Hope that helps!

Comments

Phil

For me, this works if I use the content ID method, getActiveContent(), but does NOT work if I use the file name, getActiveContentByFilename().

I am using the latest build (5.1)

September 21, 2009, 7:09 AM
Reply
Flag as Spam
Matt Levine

The filename is the part of the url past the index.cfm minus the wrapping "/"'s.

So this page's url is http://www.getmura.com/index.cfm/blog/how-to-display-content-in-another-page/

And it's filename is blog/how-to-display-content-in-another-page

September 22, 2009, 10:30 AM
Reply
Flag as Spam
Phil

Ok, so it't the complete path, not justthe name. Sorry I'm still learning mura.

September 22, 2009, 10:34 AM
Reply
Flag as Spam
Matt Levine

Try removing the spaces in the [ mura ] tags.

November 20, 2009, 7:45 AM
Reply
Flag as Spam
Kiran

I tried this in MURA using contentID but not working it is simple showing this again

[ mura ]getServiceFactory().getBean('contentManager').getActiveContent('CONTENTID', 'SITEID').getBody()[ /mura ]

November 23, 2009, 1:21 AM
Reply
Flag as Spam
Matt Levine

@kiran

Try removing the spaces in the [ mura ] tags. We put spaces in the examples to they don't get evaluated/

November 25, 2009, 2:45 AM
Reply
Flag as Spam
Jared Rypka-Hauer

Guys, this page really saved me. I was trying to add a weblink content item to simulate a link to the page with the content rather than just using the content in question in a second page.

A suggestion, though, would be to simply add a content type that is a referral, or add fields to the standard page for "filename" and "siteid" to do this automatically... I had to do it twice in the site I'm working on now so I assume this isn't an a-typical task.

Just a suggestion... maybe I'll do it myself. :) OTOH I dunno if my company would let me contribute. Either way, good stuff and thanks for the post.

January 12, 2010, 3:12 AM
Reply
Flag as Spam
Matt Levine

We've actually been considering adding a content type of "Mirror". Thanks for bringing that up!

January 12, 2010, 3:47 AM
Reply
Flag as Spam
Tom McNeer

I'd just like to +1 Jared's suggestion.

I don't think it's an uncommon scenario to want to reuse content across multiple sites (I'm currently working on a global site that will be configured as six sub-sites, and there's a lot of stuff that should be shared). And it would be great if there were a simpler way to achieve it.

February 4, 2010, 4:26 AM
Reply
Flag as Spam
Joel Richards

This is great information. Currently working on a site that will have a base site and 130 affiliate sites ( each affiliate site will be a sub domain of the default site).

So, yes! Add a content type of "mirror"!

March 3, 2010, 4:56 AM
Reply
Flag as Spam
Danaca

It would be great if there was a "mirror" content type. In the meantime, this page was very helpful.

Question though: I'm able to get the content to display, but it does not maintain the formatting. Any suggestions?

Thanks!

August 23, 2010, 5:13 AM
Reply
Flag as Spam
Sean Schroeder

Yeah, we agree. That would be nice. It's something we've been trying to get into Mura for awhile. I'm sure it will show up at some point.

Regarding your question: I would double check to make sure your CSS is set up correctly and not specific to the original page or site. Sharing content from one page to another is literally sharing the same markup and content.

August 27, 2010, 4:33 AM
Reply
Flag as Spam
Post a Comment

Required Field