如何将当前页面标题自动插入到 TYPO3 模板中? [英] How can I insert the current page title automatically into a TYPO3 template?

查看:22
本文介绍了如何将当前页面标题自动插入到 TYPO3 模板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上标题就是整个问题.

actually the title is the whole question.

我只想修改模板,以便自动显示当前页面标题(我正在使用 html 模板,所以我只需要一点打字稿即可从数据库中获取页面标题)

I just want to modify the template so that the current page title is automatically shown (i'm working with html templates so I just need the bit of typoscript to get the page title out of the database)

我希望这是可能的

推荐答案

是的.这很简单.我假设你正在使用 TemplaVoilà,因为如果你不是,你应该:-D

It is. It's pretty simple to do. I'll assume you're using TemplaVoilà, because if you're not, you should be :-D

首先在您的模板中添加一些 HTML 并使用一个虚拟页面标题.给它一个 ID 属性,以便于映射.喜欢:

Start off by putting some HTML in your template with a dummy page title. Give it an ID attribute so it's easy to map. Like:

<h1 id="page-title">Page Title Here</h1>

接下来,进入 TemplaVoilà 并将

元素映射到内容类型TypoScript 对象路径".当它提示你输入对象路径时,你可以输入任何你想要的东西——约定是动态内容被添加到lib"命名空间中,所以我们称之为lib.pagetitle.当它询问您是否要将其映射到内部"或外部"时,请选择内部"——这意味着您只是在映射

...</h1> 标签.(OUTER"意味着您要替换整个元素,包括标签,我们在这里不希望这样做,因为我们希望它保持 H1.)保存您的模板映射.

Next, go into TemplaVoilà and map that <h1> element to the content type "TypoScript Object Path". When it prompts you for the object path, you can put in anything you want -- convention is that dynamic content is added in the "lib" namespace, so let's call it lib.pagetitle. When it asks you if you want to map this to "INNER" or "OUTER", choose "INNER" -- that will mean you're just mapping the space BETWEEN the <h1>...</h1> tags. ("OUTER" means you're replacing the whole element, including the tags, which we don't want here because we want this to stay an H1.) Save your template mapping.

现在进入您网站的 TypoScript 模板.在这里,您将插入填充我们刚刚用实际内容映射的空间的逻辑.插入页面标题只需几行 TypoScript:

Now go into your site's TypoScript template. Here you're going to insert the logic that fills in that space we just mapped with actual content. To insert the page title is a matter of a couple of lines of TypoScript:

lib.pagetitle = TEXT
lib.pagetitle.data = page : title

这意味着在模板中使用我映射到 lib.pagetitle 的空间.在该空间中创建一个 TEXT 类型的内容对象.然后填充它带有页面标题的内容对象."

What this says is "take the space in the template that I mapped to lib.pagetitle. Create a content object in that space of type TEXT. Then fill that content object with the title of the page."

保存您的 TypoScript 模板.现在你完成了!

Save your TypoScript template. Now you're done!

乍一看这可能听起来很复杂,确实如此,但这个系统的好处在于它非常灵活.动态插入文本只是一个开始.TypoScript Reference(又名TSRef")包含所有详细信息——请查阅"getText" 来获取风味,该函数使 TypoScript 模板中的 "page : title" 调用放到页面标题中.

This probably sounds complicated at first glance, and it is, but the nice thing about this system is that it's amazingly flexible. Inserting text dynamically is just the beginning. The TypoScript Reference (a.k.a. the "TSRef") has all the details -- look up "getText" to get a flavor, that's the function that makes the "page : title" call in your TypoScript template drop in the page title.

TSRef 是您的朋友.我在我的办公桌上放了一份印刷版——如果你想让 TYPO3 唱歌,那它就是你的歌集.

TSRef is your friend. I keep a printed copy of it at my desk -- if you want to make TYPO3 sing, it is your songbook.

这篇关于如何将当前页面标题自动插入到 TYPO3 模板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆