Question

How can I include a page from magnolia into a magnolia template script?

In the template script with I can access data from a specific page, but how can I load that page into the template?

Let's say I have 2 pages each with its own template. Page 1 contains in its tree page 2. I want to include in the template script of page 1, page 2, but doesn't work.

Thank you very much :)

UPDATED

What I actually want to do is include my header in all of my project's pages. But I don't want to put it as a paragraph, because if I ever want to change my header, I'll have to edit all the project's pages.

So what I try to do and I don't know if this is the correct approach is to create a page template for the header. This template won't include any , or css, it's just the code for the header. The next thing I want to do is create a page in magnolia with that model to be the header. Next I'd like to include the page I've just created in my main template model for the project, but I can't figure how to do that.

I am new to Magnolia cms and initially I tried creating my demo site using stk. The only problem was that I couldn't use jsp as a scripting language, or at least I couldn't find any solution on the internet. I don't really know freemarker, but that's not really a big problem. I'm really reluctant in using freemarker because maybe in the future in a more complex project I might need some features that freemarker doesn't support, but jsp does. I'd like to build my site using jsp if that's possible with magnolia.

I'm sorry for this long update, but if anyone has any suggestions on what a best practice could be and if I could implement what I want in jsp I would be really grateful.

Thanks again for you time :)

Was it helpful?

Solution

If you're using the STK then see this guide on content-reuse.

If not have a look at the cms tag-lib, especially the tags cms:loadPage and cms:setNode with which you can get a piece of content and set it as a JSP/JSTL variable and then render it using cms:includeTemplate.

A common scenario is to 'inherit' content from the parent page, the header is an excellent example of this. What you do is for an area you walk up the content hierarchy and render everything from the parent pages in their area with the same name. This way the header which you've only added to the top page is included in all its children.

Another option is to a have special page which simply holds things to be included in other pages. Like header, footer and banners that should go in the side pane of some pages.

OTHER TIPS

Including a page within another page doesn't really work. Page 2 already has its own <html> tags, its own <script> tags, and its own CSS, so including it wholesale into another page just simply doesn't make sense.

You do, however, have a couple of options:

  1. Use an iframe. This will allow you to include the entirety of Page 2 in a region of Page 1.
  2. More recent versions of Magnolia will allow you to render an individual paragraph, which you could then include in another page. (For example, you can see a single paragraph from http://demopublic.magnolia-cms.com/demo-project/about/subsection-articles.html at http://demopublic.magnolia-cms.com/demo-project/about/subsection-articles/article/main/0.html.) This requires knowing a bit about the way the data is structured, but is a pretty useful way to be able to selectively extracts bits of a page.
  3. You can use the Magnolia API in your model class to pull data from sub-pages, and then make it available to your view template. This is the approach the STK uses to build teasers that include content from the pages they reference, and is probably the most powerful and flexible approach, but it does require actually writing some Java code. (See http://documentation.magnolia-cms.com/templating/stk/templating.html and http://documentation.magnolia-cms.com/reference/templating.html for details of how to use this approach.)
  4. (Added after question was edited) The footer functionality that's included with the STK does almost exactly this. You might be interested to take a look at that and see how it's implemented there.

Hope that helps a bit!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top