[英]How to set TYPO3 7 metatags from TypoScript RECORDS?
我正在嘗試使用TypoScript
RECORDS
對象覆蓋TYPO3 7.5
的page.meta.og:title
。
以下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實現此目的的方法?
記錄只能在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]
雖然它是您的分機,但是什么使您無法直接將其添加到動作中,而不是使用一些奇怪的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
組合不是bug,而是根據OGP Arrays規范的功能 ;)實際上,您不能用TypoScript聲明兩個相同的meta標簽是bug,原因嗎? TypoScript不是一種編程語言,它只是配置表(嚴格來說是數組)。 如我們所知,在PHP中,關聯數組的后面版本會更早地覆蓋鍵。 當我們討論og:*
metas時,我們需要記住,有時它們會在每頁中重復,並且完全有效,即: og:image
。
即使您正在使用一些現成的 ext來填充pages
記錄中的og:title
,您作為程序員的能力也要比TS中的強大得多,沒有什么阻止您使用...簡單的技巧來丟棄它的。 TS,在您的TS中添加一個條件:
[globalVar = GP:tx_myext_pi1|article > 0]
page.meta.og:title >
[end]
然后確保如開始所示將其添加到showAction
中。
最后,通過這種方式,您無需為每個具有單個視圖的模型從TS站點進行昂貴的查找(相信我,我知道這意味着什么)
順便說一句,我同意應該為此使用可靠的API,但是我為我的一個項目寫了一些ext來解決這些問題,這是數小時甚至數天的事情,如果我能找到,我將其發布到TER 。
我很快就提出了我的問題:)
這可以通過使用寄存器來實現,下面是一個示例:
[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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.