1

我正在尝试用一个对象覆盖page.meta.og:titlein 。TYPO3 7.5TypoScript RECORDS

不幸的是,以下TypoScript代码段似乎不起作用:

[globalVar = GP:tx_myext_pi1|article > 0]

    temp.newsTitle = RECORDS
    temp.newsTitle {
        dontCheckPid = 1
        tables = tx_myext_domain_model_article
        source.data = GP:tx_myext_pi1|article
        source.intval = 1
        conf.tx_myext_domain_model_article = TEXT
        conf.tx_myext_domain_model_article {
            stdWrap.field = title
            stdWrap.wrap = |
        }
    }

    # Overrides the template pageTitle
    page.10.variables.pageTitle >
    page.10.variables.pageTitle < temp.newsTitle

    # Overrides the meta og:title   
    page.meta.og:title >
    page.meta.og:title < temp.newsTitle

[global]

我得到:

<meta name="og:title" content="RECORDS">

虽然页面标题的覆盖对我有用。

有什么方法可以用 TypoScript 实现这一点吗?

4

3 回答 3

3

RECORDS 仅适用于 cObject。 https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Records/Index.html

[globalVar = GP:tx_myext_pi1|article > 0]
    page.meta{
        og:title {
        attribute = property
            stdWrap.cObject = RECORDS
            stdWrap.cObject {
                source = {GP:tx_myext_pi1|article}
                source.insertData = 1
                tables = tx_myext_domain_model_article
                conf.tx_myext_domain_model_article= TEXT
                conf.tx_myext_domain_model_article.field = title
            }
        }
[global]
于 2016-08-24T21:21:19.627 回答
1

虽然这是您的分机,但阻止您直接在操作中添加它而不是使用一些奇怪的 TS 进行操作?;)

public function showAction($article) {
    $ogTitle = trim(htmlentities($article->getTitle()));
    $GLOBALS['TSFE']->getPageRenderer()->addMetaTag('<meta name="og:title" content="' . $ogTitle . '">');

    // ... rest of action
}

还可以看看 Georg Ringer 的News扩展,看看他是如何使用metaTagViewHeplper的(实际上他也在做同样的事情,但在 VH 中)——你可以用它来收集og视图上的其他标签,比如og:image和其他。

编辑:

更多关于防止重复条目

请记住,重复的meta组合不是错误,它是根据OGP Arrays 规范的功能;)实际上,您不能使用 TypoScript 声明两个相同的元标记是一个错误,原因是什么?TypoScript 不是一种编程语言,它只是配置表(严格来说是数组)。正如我们在 PHP 中的关联数组中所知道的,稍后的键覆盖更早。当我们讨论元数据时,og:*我们需要记住,有时它们会在每页重复,这是完全有效的,即:og:image.

作为一个程序员,你在你的行动中比在 TS 中拥有更多的权力,即使你正在使用一些从记录中填充的现成的ext ,也没有什么能阻止你用......在 TS 中的简单技巧,在你的TS 添加条件:og:titlepages

[globalVar = GP:tx_myext_pi1|article > 0]
  page.meta.og:title >
[end]

然后确保您将其添加到您showAction的开头所示。

最后,您不需要从 TS 站点为每个具有单个视图的模型进行昂贵的查找(相信我,我知道这意味着什么)

顺便说一句,我同意这应该有可靠的 API,但是我为我的一个项目写了一些 ext 来处理这些事情,那是几个小时甚至几天的问题,如果我能找到它,我会把它发布到 TER .

于 2015-10-08T18:11:15.593 回答
0

我要快速发布我的问题:)

这可以通过使用寄存器来实现,这里是一个例子:

[globalVar = GP:tx_myext_pi1|article > 0]

    page.9 = LOAD_REGISTER
    page.9 {
        newsTitle.cObject = RECORDS
        newsTitle.cObject {
            dontCheckPid = 1
            tables = tx_myext_domain_model_article
            source.data = GP:tx_myext_pi1|article
            source.intval = 1
            conf.tx_myext_domain_model_article = TEXT
            conf.tx_myext_domain_model_article {
                stdWrap.field = title
                stdWrap.wrap = |
            }
        }
    }

    page.10.variables.pageTitle >
    page.10.variables.pageTitle = TEXT
    page.10.variables.pageTitle {
        data = register:newsTitle
    }

    page.meta.og:title >
    page.meta.og:title {
        attribute = property
        override.data = register:newsTitle
    }

[global]
于 2015-10-08T14:32:59.680 回答