ezplatform使用内容类型

时间:2017-08-24 08:40:20

标签: php symfony ezpublish ezplatform

现在有人知道为ez平台创建自定义视图类型吗?默认3已经用尽,我们需要一个新的'链接' 或者,是否有人知道如何将render( controller(与自定义模板一起使用,因为这也会立即解决阻止。

基本上,我们在使用的内容对象中有一个多关系字段,我们需要打印到所有相关contentIds的链接,路径工作得很好,但我们找不到一种方法来提取链接的内容对象的名称做一些相当时髦的tpl逻辑传递params。

EG:作为现在的黑客,我们可以将“embed_type”作为自定义参数传递给render(controller("ez_content:viewAction",以便为特定内容类型和视图类型提供内容对象的备用视图。

{% if embed_type is defined %}
    {% include "embed/#{embed_type}.html.twig" %}
{% else %}
        <h1>{{ ez_field_value( content, 'name') }}</h1>
{% endif %}

然而,这非常难看,我们真正想做的就是为所有内容类型使用1个模板,所以我们需要做的就是遍历关系字段和打印链接(作为内容字段中唯一可用的内容) :“目的地ID”)。我确信文档中曾经有过这个选项,但我再也找不到它了,例如:

{% set links =  ez_field_value( footer, "first_links_row" ).destinationContentIds%}
{% for id in links %}
   {{ render(controller("ez_content:viewAction", {"contentId": id, "template": "link.html.twig"})) }}
{% endfor %}

link.html.twig可以简单地打印链接:

<a href="{{ path( "ez_urlalias", {"contentId": id} ) }}">
   {{ ez_field_value( content, "name" ) }}
</a>

如果使用render (controller (帮助程序无法使用自定义tpl,则新的自定义视图类型也可以解决此问题,但我找不到任何文档。

1 个答案:

答案 0 :(得分:3)

您可以创建一个twig function来做到这一点。我们有这样的事情:

定义:

new Twig_SimpleFunction(
   'content_name',
    array($this, 'getContentName')
),

实现:

public function getContentName($content, $forcedLanguage = null)
{
    if (!$content instanceof Content && !$content instanceof ContentInfo) {
        $contentInfo = $this->repository->getContentService()->loadContentInfo($content);
    } elseif ($content instanceof Content) {
        $contentInfo = $content->contentInfo;
    } else {
        $contentInfo = $content;
    }

    return $this->translationHelper->getTranslatedContentNameByContentInfo($contentInfo, $forcedLanguage);
}

可让您提供内容ID,内容信息或内容本身,并返回已翻译的内容名称

相关问题