0

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

基本上,我们在使用的内容对象中有一个多关系字段,我们需要打印指向所有相关 contentIds 的链接,路径效果很好,但是我们找不到一种方法来提取链接的内容对象的名称而不做一些公平的事情传入参数的时髦 tpl 逻辑。

EG:作为一个 hack,我们现在可以将“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 个模板,所以我们需要做的就是遍历关系字段并打印链接(作为内容字段中唯一可用的东西:“destination身份证”)。我确定文档中曾经有此选项,但我再也找不到它了,例如:

{% 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>

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

4

1 回答 1

3

您可以创建一个可以做到这一点的树枝函数。我们有这样的东西:

定义:

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、内容信息或内容本身,并返回翻译后的内容名称

于 2017-08-24T08:59:39.453 回答