【问题标题】:EzPublish render searchHits in TwigEzPublish 在 Twig 中渲染 searchHits
【发布时间】:2015-08-31 07:12:25
【问题描述】:

我有以下代码来检索我的 EzPublish 5.4 网站上的主菜单:

$query = new LocationQuery();
    $query->query = new Criterion\LogicalAnd(
        array(
            new Criterion\ContentTypeIdentifier( $this->getTopMenuContentTypeIdentifierList() ),
            new Criterion\Visibility( Criterion\Visibility::VISIBLE ),
            new Criterion\Location\Depth(
                Criterion\Operator::BETWEEN,
                array( $rootLocation->depth + 1, $rootLocation->depth + 3 )
            ),
            new Criterion\Subtree( $rootLocation->pathString ),
            new Criterion\LanguageCode( $configResolver->getParameter( 'languages' ) )
        )
    );
    $query->sortClauses = array( new Query\SortClause\Location\Depth(), new Query\SortClause\Location\Priority() );
    $main_menu = $searchService->findLocations( $query )->searchHits;

这行得通,我得到了我期望的所有结果,现在我将此数组提供给我的 Twig 模板:

{% for item in menu %}
<a href="#menuitemurl">Menu item title in current language</a>
{% endfor %}

两个问题: 1:如何获取要在 Twig 中呈现的 SearchHit 的 URL?我不知道从哪里得到这个,谷歌没有帮助 2:如何获取当前站点语言的SearchHit的标题?我的网站是多语言的,每个项目都提供瑞典语和英语,但不知何故,即使我使用瑞典语版本,我也只能获得带有上述代码的英文标题

【问题讨论】:

标签: php symfony twig ezpublish


【解决方案1】:

你可以像这样加载相应的内容对象:

$contentList = [];
foreach ( $searchService->findLocations( $query )->searchHits as $hit )
{
    $contentList[] = $this->contentService->loadContent( $hit->valueObject->contentInfo->id );
};

并将$contentList[] 传递给模板。然后用它来获取内容的完整 URL。

或根据您的 searchHits 中的内容 ID 在模板中呈现内容。

【讨论】:

    猜你喜欢
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    相关资源
    最近更新 更多