如何将当前页面标题自动插入到 TYPO3 模板中?

发布于 2024-08-02 00:34:03 字数 108 浏览 9 评论 0原文

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

我只是想修改模板,以便自动显示当前页面标题(我正在使用 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 技术交流群。

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

发布评论

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

评论(8

故事与诗 2024-08-09 00:34:03

这是。 做起来非常简单。 我假设您正在使用 TemplaVoilà,因为如果您没有使用,那么您应该 :-D

首先在模板中添加一些带有虚拟页面标题的 HTML。 为其指定一个 ID 属性,以便于映射。 就像:

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

接下来,进入 TemplaVoilà 并将

元素映射到内容类型“TypoScript Object Path”。 当它提示您输入对象路径时,您可以输入任何您想要的内容 - 约定是动态内容添加到“lib”命名空间中,所以我们将其称为 lib.pagetitle。 当它询问您是否要将其映射到“INNER”或“OUTER”时,请选择“INNER”——这意味着您只是映射

... 标签。 (“OUTER”意味着您要替换整个元素,包括标签,我们在这里不需要它,因为我们希望它保留为 H1。)保存您的模板映射。

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

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

这意味着“在模板中占据我映射到 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:

<h1 id="page-title">Page Title Here</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.

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

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."

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.

如此安好 2024-08-09 00:34:03

我更喜欢 vhs 解决方案:

{v:page.info(field:'title')}

https://fluidtypo3.org/viewhelpers/vhs/master /Page/InfoViewHelper.html

I prefer the vhs solution:

{v:page.info(field:'title')}

https://fluidtypo3.org/viewhelpers/vhs/master/Page/InfoViewHelper.html

入怼 2024-08-09 00:34:03

如果您想在流畅的页面模板中使用它,您也可以简单地使用:

{data.title}

访问页面标题。

If you want to use this in a fluid page template, you can also simple use:

{data.title}

to access the page title.

爱已欠费 2024-08-09 00:34:03
lib.pagetitle = RECORDS
lib.pagetitle {
    source.data = page:uid
    tables = pages
    conf.pages = TEXT
    conf.pages.field = nav_title
}

要获取当前页面标题:

lib.pagetitle = TEXT
lib.pagetitle.field=title

对于元数据:

当我们浏览移动兼容网站时,将元放在标题标记之后非常重要

为了防止 IE9 中的怪异模式,我需要在每个 HTML 页面的最顶部添加以下行:

您可以通过在打字稿中添加 disableAllHeaderCode = 1 来自己编写整个标头,也可以通过将元标记直接添加到 head 标记来破解它:

 page.headTag = <head><meta http-equiv="X-UA-Compatible" content="IE=edge" />

将其放在您的打字稿

 meta.X-UA-Compatible = IE=edge,chrome=1

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>

lib.pagetitle = RECORDS
lib.pagetitle {
    source.data = page:uid
    tables = pages
    conf.pages = TEXT
    conf.pages.field = nav_title
}

To get current page title:

lib.pagetitle = TEXT
lib.pagetitle.field=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:

 page.headTag = <head><meta http-equiv="X-UA-Compatible" content="IE=edge" />

Place this at your typoscript

 meta.X-UA-Compatible = IE=edge,chrome=1

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/

牵你手 2024-08-09 00:34:03

您可以通过以下typoscript:当前页面标题,

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

然后使用typoscriptObjectPath将此对象用于您的页面,如下所示:

<f:cObject typoscriptObjectPath="lib.pagetitle"/>

You can current page title by following typoscript:

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

and then use this object to your page using typoscriptObjectPath like following way:

<f:cObject typoscriptObjectPath="lib.pagetitle"/>
泡沫很甜 2024-08-09 00:34:03

如果您想使用仅fluid解决方案,请安装VHS扩展,然后您可以输出页面标题而不使用任何TypoScript,如下所示:

标签示例:

<v:page.header.title title="NULL" whitespaceString="' '" setIndexedDocTitle="1">
  <!-- tag content - may be ignored! -->
</v:page.header.title>

内联示例:

{v :page.header.title(标题:'NULL',whitespaceString:'''',setIndexedDocTitle:1)}

If you want to use a fluid only solution, install the VHS extension and you can output the page title without using any TypoScript at all like this:

Tag Example:

<v:page.header.title title="NULL" whitespaceString="' '" setIndexedDocTitle="1">
  <!-- tag content - may be ignored! -->
</v:page.header.title>

Inline Example:

{v:page.header.title(title: 'NULL', whitespaceString: '' '', setIndexedDocTitle: 1)}

葮薆情 2024-08-09 00:34:03
lib.page_title = CONTENT
lib.page_title {

    table = pages

    select {
        where = uid = 2
    }

    renderObj = COA
    renderObj {

        10 = TEXT
        10 {
            field = title
            wrap = <h1 class="page_title">|</h1>
        }

        20 = TEXT
        20 {
            field = subtitle
            stdWrap.required = 1
            stdWrap.wrap = <h5>|</h5>
        }
    }
}

调用 lib.page_title 想要用此行渲染打字稿的地方

<f:cObject typoscriptObjectPath='lib.page_title' />

我希望这有帮助!

lib.page_title = CONTENT
lib.page_title {

    table = pages

    select {
        where = uid = 2
    }

    renderObj = COA
    renderObj {

        10 = TEXT
        10 {
            field = title
            wrap = <h1 class="page_title">|</h1>
        }

        20 = TEXT
        20 {
            field = subtitle
            stdWrap.required = 1
            stdWrap.wrap = <h5>|</h5>
        }
    }
}

call the lib.page_title where want to render typoscript with this lines

<f:cObject typoscriptObjectPath='lib.page_title' />

I hope this helps !!!

水晶透心 2024-08-09 00:34:03

这个问题很老了,但我仍然想添加一些我从未在这里读过的内容。

TYPO3 提供了许多有关标题的内容,而且它也可以使其完全独立,这是正确的。 然而,TYPO3 的所有不错的选项或多或少都被单独的解决方案禁用了。

首先是对问题的直接回答:
默认的页面标题可以这样覆盖

config.pageTitle.stdWrap.override.cObject < lib.pagetitle

如果定义了多种页面类型并且应为每种类型单独设置标题,则可以在页面定义中注明配置:

page = PAGE
page {
    typeNum = 0
    config.pageTitle.stdWrap.override.cObject < lib.pagetitle_1
    ...
}

anotherPage = PAGE
anotherPage {
    typeNum = 1
    config.pageTitle.stdWrap.override.cObject < lib.pagetitle_2
    ...
}

下面仍然是一个 lib.pagetitle这不仅仅是使用标题或副标题 - 如果在页面上使用扩展名,它会使用新闻标题:

lib.pagetitle = COA
lib.pagetitle {

  10 = TEXT
  10 {
    // subtitle: used as field for title tag
    value.field = subtitle // title
    if.isFalse.data = GP:tx_news_pi1|news
  }

  20 = RECORDS
  20 {
        if.isTrue.data = GP:tx_news_pi1|news
        dontCheckPid = 1
        tables = tx_news_domain_model_news
        source.data = GP:tx_news_pi1|news
        source.intval = 1
        conf.tx_news_domain_model_news = TEXT
        conf.tx_news_domain_model_news {
            field = title
            htmlSpecialChars = 1
        }
    }
 }

现在还有一些背景,为什么我认为某些单独的标题可能不是最好的解决方案:

  • TYPO3 通常会添加几个细节标题,这很有用,不需要将这些东西单独组合起来。
  • 脚本和样式表是有组织的,甚至可以通过 TypoScript 压缩和合并。 如果遵循某种语法,它甚至会注意像 jquery 这样的库只包含一次。
  • TYPO3 在 TypoScript 中具有许多功能,其中所有内容都可以定义与标题相关的内容,并且还可以决定脚本是否可能永远不会包含在标题中,而是包含在页面源的底部。
  • 可以定义元标签(并通过扩展或子模板覆盖)

在我看来,在自己的模板中再次手动实现整个逻辑没有用,我认为标题应该仅针对特殊页面类型(如 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

config.pageTitle.stdWrap.override.cObject < lib.pagetitle

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:

page = PAGE
page {
    typeNum = 0
    config.pageTitle.stdWrap.override.cObject < lib.pagetitle_1
    ...
}

anotherPage = PAGE
anotherPage {
    typeNum = 1
    config.pageTitle.stdWrap.override.cObject < lib.pagetitle_2
    ...
}

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:

lib.pagetitle = COA
lib.pagetitle {

  10 = TEXT
  10 {
    // subtitle: used as field for title tag
    value.field = subtitle // title
    if.isFalse.data = GP:tx_news_pi1|news
  }

  20 = RECORDS
  20 {
        if.isTrue.data = GP:tx_news_pi1|news
        dontCheckPid = 1
        tables = tx_news_domain_model_news
        source.data = GP:tx_news_pi1|news
        source.intval = 1
        conf.tx_news_domain_model_news = TEXT
        conf.tx_news_domain_model_news {
            field = title
            htmlSpecialChars = 1
        }
    }
 }

Now still some background why I think some individual header might not be the best solution:

  • TYPO3 usually adds several details to the header, that are useful and it's not required to combine those things individually new.
  • Scripts and stylesheets are organized and can be even by TypoScript compressed and merged. If some syntax is followed it even takes care that a library like jquery is only included once.
  • TYPO3 has many functions in TypoScript where everything can be defined related to the header and also it can be decided if scripts shall be perhaps never be included at all in the header but instead in the bottom of the page-source.
  • Metatags can be defined (and overridden by extensions or sub-templates)

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

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