Php ezplatform呈现内容类型中多关系内容项的url和对象名链接
现在有人知道为ez平台创建自定义视图类型吗?默认3已用尽,我们需要一个新的“链接” 或者,是否有人知道如何将Php ezplatform呈现内容类型中多关系内容项的url和对象名链接,php,symfony,ezpublish,ezplatform,Php,Symfony,Ezpublish,Ezplatform,现在有人知道为ez平台创建自定义视图类型吗?默认3已用尽,我们需要一个新的“链接” 或者,是否有人知道如何将渲染(控制器()与自定义模板一起使用,因为这也将立即解决out块 基本上,我们在使用的内容对象中有一个多关系字段,我们需要打印到所有相关ContentID的链接,path工作得很好,但我们无法找到一种方法来提取链接的内容对象的名称,而不执行一些相当时髦的传递参数的tpl逻辑 例如:现在我们可以通过render(controller)(“ez_content:viewAction”)将“em
渲染(控制器(
)与自定义模板一起使用,因为这也将立即解决out块
基本上,我们在使用的内容对象中有一个多关系字段,我们需要打印到所有相关ContentID的链接,path工作得很好,但我们无法找到一种方法来提取链接的内容对象的名称,而不执行一些相当时髦的传递参数的tpl逻辑
例如:现在我们可以通过render(controller)(“ez_content:viewAction”
)将“embed_type”作为一个自定义参数传入,以便为特定内容类型和视图类型的内容对象引入另一个视图
{% if embed_type is defined %}
{% include "embed/#{embed_type}.html.twig" %}
{% else %}
<h1>{{ ez_field_value( content, 'name') }}</h1>
{% endif %}
其中link.html.twig将简单打印链接:
<a href="{{ path( "ez_urlalias", {"contentId": id} ) }}">
{{ ez_field_value( content, "name" ) }}
</a>
如果无法在渲染(控制器(
辅助程序)中使用自定义tpl,则新的自定义视图类型也会解决此问题,但我找不到这两个类型的文档。您可以创建一个可以解决此问题的视图。我们有如下功能:
定义:
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、内容信息或内容本身,并返回翻译后的内容名称您可以创建一个这样做的名称。我们有如下内容:
定义:
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、内容信息或内容本身,并返回翻译后的内容名称
使用eZ\Publish\API\Repository\Repository;使用eZ\Publish\API\Repository\Values\content\content;使用eZ\Publish\API\Repository\TranslationService;
?是,s对不起,这些use语句至少是需要的:)(如果有其他人偶然发现了相同的问题,只是为了完整的AppExtension
\uu构造;)谢谢你的回答,让它工作起来。使用eZ\Publish\Core\Helper\TranslationHelper;
不eZ\Publish\API\Repository\TranslationService;
使用eZ\Publish\API\Repository\Repository;使用eZ\Publish\API\Repository\Values\Content\Content;使用eZ\Publish\API\Repository\ContentInfo\Repository\TranslationService;?是的,很抱歉,这些use语句至少是必需的:)(如果其他人偶然发现同样的问题,只是为了完整地理解AppExtension
\uu构造;)谢谢你的回答,让它工作起来。use eZ\Publish\Core\Helper\TranslationHelper;
noteZ\Publish\API\Repository\TranslationService;