如何将当前页面标题自动插入到 TYPO3 模板中?
实际上标题就是整个问题。
我只是想修改模板,以便自动显示当前页面标题(我正在使用 html 模板,所以我只需要一些打字稿即可从数据库中获取页面标题)
我希望这是可能的
actually the title is the whole question.
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)
I hope that's possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这是。 做起来非常简单。 我假设您正在使用 TemplaVoilà,因为如果您没有使用,那么您应该 :-D
首先在模板中添加一些带有虚拟页面标题的 HTML。 为其指定一个 ID 属性,以便于映射。 就像:
接下来,进入 TemplaVoilà 并将
元素映射到内容类型“TypoScript Object Path”。 当它提示您输入对象路径时,您可以输入任何您想要的内容 - 约定是动态内容添加到“lib”命名空间中,所以我们将其称为
lib.pagetitle
。 当它询问您是否要将其映射到“INNER”或“OUTER”时,请选择“INNER”——这意味着您只是映射...
标签。 (“OUTER”意味着您要替换整个元素,包括标签,我们在这里不需要它,因为我们希望它保留为 H1。)保存您的模板映射。现在进入您网站的 TypoScript 模板。 在这里,您将插入填充我们刚刚用实际内容映射的空间的逻辑。 插入页面标题只需几行 TypoScript:
这意味着“在模板中占据我映射到
lib.pagetitle
的空间。在该空间中创建一个内容对象输入TEXT
。然后用页面标题填充该内容对象。”保存您的 TypoScript 模板。 现在你完成了!
乍一看这可能听起来很复杂,确实如此,但这个系统的好处在于它非常灵活。 动态插入文本仅仅是开始。 TypoScript 参考(又名“TSRef”)包含所有详细信息 - 请查找“ getText”来获得风味,该函数使 TypoScript 模板中的“page : title”调用放入页面标题中。
TSRef 是你的朋友。 我在我的办公桌上放了一本它的印刷版——如果你想让 TYPO3 唱歌,它就是你的歌集。
It is. It's pretty simple to do. I'll assume you're using TemplaVoilà, because if you're not, you should be :-D
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:
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 itlib.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.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:
What this says is "take the space in the template that I mapped to
lib.pagetitle
. Create a content object in that space of typeTEXT
. Then fill that content object with the title of the page."Save your TypoScript template. Now you're done!
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 is your friend. I keep a printed copy of it at my desk -- if you want to make TYPO3 sing, it is your songbook.
我更喜欢 vhs 解决方案:
https://fluidtypo3.org/viewhelpers/vhs/master /Page/InfoViewHelper.html
I prefer the vhs solution:
https://fluidtypo3.org/viewhelpers/vhs/master/Page/InfoViewHelper.html
如果您想在流畅的页面模板中使用它,您也可以简单地使用:
访问页面标题。
If you want to use this in a fluid page template, you can also simple use:
to access the page title.
要获取当前页面标题:
对于元数据:
当我们浏览移动兼容网站时,将元放在标题标记之后非常重要
为了防止 IE9 中的怪异模式,我需要在每个 HTML 页面的最顶部添加以下行:
您可以通过在打字稿中添加 disableAllHeaderCode = 1 来自己编写整个标头,也可以通过将元标记直接添加到 head 标记来破解它:
将其放在您的打字稿
httpEquivalent 处:(自 TYPO3 起) 4.7) 如果设置为 1,则在元标记中使用 http-equiv 属性而不是“name”属性。 默认值:0。
有关 TYPO3 内容的更多信息,您可以访问我的博客
https://jainishsenjaliya.wordpress.com/2013/10/10/put-meta-tag-on-top-of-header-section-in-typo3/< /a>
To get current page title:
For meta data :
Its very important to place meta after header tag when we are gone through mobile compatible website
In order to prevent quirks mode in IE9 I need to add this lines at the very top of every HTML page:
You can write the whole header by yourself, by adding disableAllHeaderCode = 1 to your typoscript or you can hack it by adding your meta tag directly to the head tag:
Place this at your typoscript
httpEquivalent: (Since TYPO3 4.7) If set to 1, the http-equiv attribute is used in the meta tag instead of the “name” attribute. Default: 0.
For more information about TYPO3 stuff you may visit my blog
https://jainishsenjaliya.wordpress.com/2013/10/10/put-meta-tag-on-top-of-header-section-in-typo3/
您可以通过以下typoscript:当前页面标题,
然后使用typoscriptObjectPath将此对象用于您的页面,如下所示:
You can current page title by following typoscript:
and then use this object to your page using typoscriptObjectPath like following way:
如果您想使用仅
fluid
解决方案,请安装VHS
扩展,然后您可以输出页面标题而不使用任何TypoScript
,如下所示:标签示例:
内联示例:
{v :page.header.title(标题:'NULL',whitespaceString:'''',setIndexedDocTitle:1)}
If you want to use a
fluid
only solution, install theVHS
extension and you can output the page title without using anyTypoScript
at all like this:Tag Example:
Inline Example:
{v:page.header.title(title: 'NULL', whitespaceString: '' '', setIndexedDocTitle: 1)}
调用 lib.page_title 想要用此行渲染打字稿的地方
我希望这有帮助!
call the lib.page_title where want to render typoscript with this lines
I hope this helps !!!
这个问题很老了,但我仍然想添加一些我从未在这里读过的内容。
TYPO3 提供了许多有关标题的内容,而且它也可以使其完全独立,这是正确的。 然而,TYPO3 的所有不错的选项或多或少都被单独的解决方案禁用了。
首先是对问题的直接回答:
默认的页面标题可以这样覆盖
如果定义了多种页面类型并且应为每种类型单独设置标题,则可以在页面定义中注明配置:
下面仍然是一个
lib.pagetitle
这不仅仅是使用标题或副标题 - 如果在页面上使用扩展名,它会使用新闻标题:现在还有一些背景,为什么我认为某些单独的标题可能不是最好的解决方案:
在我看来,在自己的模板中再次手动实现整个逻辑没有用,我认为标题应该仅针对特殊页面类型(如 AJAX 或动态 PDF 文件)禁用。 这是我认为该选项有用的主要原因。
她仍然是有关 TypoScript 中的
config
-options 的最新文档的当前链接(锚页面标题):https://docs.typo3.org/typo3cms/TyposcriptReference/设置/配置/Index.html#pagetitle
The question is quite old but I still want to add something I never read here.
TYPO3 offers many things concerning the header, and it's right that it's also possible to render it completely individual. Nevertheless all the nice options of TYPO3 are more or less disabled by the individual solution.
So first the direct answer on the question:
The default page title can be overridden like this
If several page types are defined and the title shall be set individually for each type, the configuration can be noted inside the page-definitions:
Below still a
lib.pagetitle
which makes a little bit more than only using title or subtitle - it uses news-title if the extension is used on a page:Now still some background why I think some individual header might not be the best solution:
Implementing this whole logic manually again in an own template in my opinion is not useful and I think headers should be only disabled for special page-types like AJAX or dynamic PDF-files. This is the primary reason that I consider that option as useful.
Her still the current link for the most recent documentation about the
config
-options in TypoScript (anchor pagetitle):https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#pagetitle