检查 Contao fe_page 模板中的条件

Checking conditions in fe_page template for Contao

我现在正在使用 contao fe_page 模板来生成元标记。现在我需要根据条件显示元标记。即

    if (condition a){
        meta tag =a
}
else {
        meta tag = b
}

条件为"whether the news module is used in that page or not"。 如何检查 fe_page 模板中的数据条件?有解决办法吗?

您可以在 news_full 模板中执行以下操作,而不是在您的 fe_page 模板中检查它:

<?php

if ($this->addImage)
{
    $GLOBALS['TL_HEAD'][] = '<meta name="twitter:card" content="summary_large_image">';
    $GLOBALS['TL_HEAD'][] = '<meta name="twitter:image" content="' . $this->singleSRC . '">';
}

如您所见,这还添加了一个 twitter:image 带有新闻文章预告图片的元属性。

除了在 news_full 模板中执行此操作外,您还可以在 parseArticle 挂钩中执行此操作,这样您可以在需要时进行更多控制。