现在有没有人知道如何为ez平台创建自定义视图类型?默认的3已经用完了,我们需要一个新的‘链接’或者,有谁知道如何使用自定义模板的render( controller(,因为这也将解决块现在。
基本上,我们在使用的content对象中有一个多关系字段,我们需要打印到所有相关contentIds的链接,path很好用,但是我们无法找到一种方法来提取链接的content对象的名称,而不做一些相当时髦的传递参数的第三方逻辑。
作为一个技巧,现在我们可以将"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 %}然而,这是非常丑陋的,我们真正想做的就是为所有内容类型使用一个模板,所以我们所需要做的就是遍历关系字段并打印链接(作为内容字段中唯一可用的东西:“目标ids")。我确信在文档中曾经有过这个选项,但是我再也找不到它了,例如:
{% 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 (帮助器中不能使用定制的第三方公共许可证,那么新的定制视图类型也可以解决这个问题,但我找不到这两种视图类型的文档。
发布于 2017-08-24 16:59:39
您可以创建一个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、内容信息或内容本身,并返回翻译后的内容名称。
https://stackoverflow.com/questions/45856839
复制相似问题