在 Magnolia cms 中的模板脚本中包含页面

发布于 2024-12-19 17:09:03 字数 730 浏览 7 评论 0原文

如何将 Magnolia 的页面包含到 Magnolia 模板脚本中?

在模板脚本中,我可以访问特定页面的数据,但如何将该页面加载到模板中?

假设我有 2 个页面,每个页面都有自己的模板。第 1 页包含在其树中第 2 页。我想包含在第 1 页、第 2 页的模板脚本中,但不起作用。

非常感谢:)

更新

我真正想做的是将我的标题包含在我的项目的所有页面中。但我不想把它作为一个段落,因为如果我想更改标题,我将不得不编辑项目的所有页面。

因此,我尝试做的(但我不知道这是否是正确的方法)是为标题创建页面模板。该模板不会包含任何 , 或 css ,它只是标题的代码。 我想做的下一件事是在 Magnolia 中创建一个页面,并以该模型作为标题。 接下来,我想将刚刚创建的页面包含在项目的主模板模型中,但我不知道如何做到这一点。

我是 Magnolia cms 的新手,最初我尝试使用 stk 创建演示网站。唯一的问题是我无法使用jsp作为脚本语言,或者至少我在互联网上找不到任何解决方案。我不太了解 freemarker,但这并不是一个大问题。我真的很不愿意使用freemarker,因为也许将来在一个更复杂的项目中我可能需要一些freemarker不支持的功能,但jsp支持。如果可以的话,我想使用 jsp 构建我的网站。

我对这么长的更新感到抱歉,但是如果有人对最佳实践有任何建议,并且如果我可以在 jsp 中实现我想要的内容,我将非常感激。

再次感谢您抽出时间:)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日暮斜阳 2024-12-26 17:09:03

如果您使用 STK,请参阅内容重用。

如果没有,请查看 cms tag-lib,尤其是 cms:loadPage 和 cms:setNode 标签,您可以使用它们获取一段内容并将其设置为 JSP/JSTL 变量然后使用 cms:includeTemplate 渲染它。

一个常见的场景是从父页面“继承”内容,标题就是一个很好的例子。您所做的就是对于一个区域,您沿着内容层次结构向上移动,并以相同的名称呈现其区域中父页面中的所有内容。这样,您仅添加到顶部页面的标题将包含在其所有子页面中。

另一种选择是有一个特殊的页面,它只保存要包含在其他页面中的内容。像页眉、页脚和横幅一样,应该放在某些页面的侧窗格中。

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.

白云不回头 2024-12-26 17:09:03

将一个页面包含在另一个页面中实际上并不起作用。第 2 页已经有自己的 了标签,它自己的

不过,您有几个选择:

  1. 使用 iframe。这将允许您将整个第 2 页包含在第 1 页的区域中。
  2. 最新版本的 Magnolia 将允许您呈现单个段落,然后您可以将其包含在另一个页面中。 (例如,您可以看到 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。)这需要了解一些数据的结构方式,但这是一种能够有选择地提取位的非常有用的方法一个页面的。
  3. 您可以在模型类中使用 Magnolia API 从子页面提取数据,然后将其提供给视图模板。这是 STK 用于构建包含其引用页面内容的预告片的方法,并且可能是最强大和最灵活的方法,但它确实需要实际编写一些 Java 代码。 (请参阅 http://documentation.magnolia-cms.com/templatating/stk/templated .htmlhttp://documentation.magnolia-cms.com/reference/templatating.html 了解如何使用此方法的详细信息。)
  4. (编辑问题后添加)包含的页脚功能STK 几乎就是这样做的。您可能有兴趣查看它并了解它是如何实现的。

希望能有所帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文