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 ]


[ 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!


Post a Comment

Required Field