triniti/curator

此包已被弃用,不再维护。作者建议使用 triniti/core 包。

PHP 库,提供 triniti:curator 架构的实现。

v1.4.10 2020-11-18 21:29 UTC

README

Build Status

PHP 库,提供 triniti:curator 架构的实现。使用此库假设您已经使用 Pbjc 创建并编译了自己的 pbj 类,并正在使用来自 triniti/schemas"triniti:curator:mixin:*" 混合。

Symfony 集成

在 Symfony 应用中启用这些服务是通过导入类并让 Symfony 自动配置和自动注入它们来完成的。

config/packages/curator.yml

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

  Triniti\Curator\:
    resource: '%kernel.project_dir%/vendor/triniti/curator/src/**/*'

Twig 扩展

提供了一些 Twig 函数来简化推广和小部件的渲染。

如果使用 Symfony 自动注入,则自动可用 Twig 扩展。

Twig 函数: curator_find_promotion

如果找到,则返回给定槽位的推广。

参数

  • string $slot

示例

# page.html.twig

{# one promotion for the entire desktop-home screen #}
{% set promotion = curator_find_promotion("#{device_view}-home") %}

{{ curator_render_promotion_slots(promotion, {promotion_slot: 'header', section: 'header'}) }}
{{ curator_render_promotion_slots(promotion, {promotion_slot: 'footer', section: 'footer'}) }}

</body>
</html>

Twig 函数: curator_render_widget

使用具有 triniti:curator:mixin:render-widget-request 混合的请求渲染小部件。返回响应中的 html 字段(具有 triniti:curator:mixin:render-widget-response 混合),并使用 twig 渲染原始值。

参数

  • Widget|NodeRef|array|string $widget
  • RenderContext|array $context = []
  • bool $returnResponse = false 当您想要原始渲染响应时使用。

示例

# page.html.twig

{{ curator_render_widget('acme:slider-widget:4d2dd0bf-70af-4f5e-875b-fcd7db73fb78', {
  section: 'permalink',
  booleans: {
    enable_ads: true,
    dnt: false,
    autoplay_videos: false,
  },
  strings: {
    custom1: 'val1',
    custom2: 'val2',
    customN: 'val3',
  },
}) }}

</body>
</html>

此函数将使用 Twig 渲染小部件,通过解析上下文和小部件类型到 Twig 模板。请求的文件名必须在 Twig 的 命名空间路径 @curator_widgets 中。所有部分都是可选的,除了平台,默认为 "web"。

使用第一个找到的模板

  • @curator_widgets/{$platform}/{$section}/{$widgetName}/{$widgetName}.{$deviceView}.twig
  • @curator_widgets/{$platform}/{$section}/{$widgetName}/{$widgetName}.twig
  • @curator_widgets/{$platform}/{$blockName}/{$widgetName}.{$deviceView}.twig
  • @curator_widgets/{$platform}/{$blockName}/{$widgetName}.twig
  • @curator_widgets/{$platform}/missing_widget.twig

输出示例

例如 @curator_widgets/web/blogroll/slider_widget/slider_widget.smartphone.twig

$output = $this->twig->render($name, [
    'pbj'             => $widget,
    'pbj_name'        => $widgetName, // e.g. slider_widget
    'context'         => $context,
    'render_request'  => $request,
    'search_response' => $searchResponse,
    'has_nodes'       => $hasNodes,
    'device_view'     => $context->get('device_view'),
    'viewer_country'  => $context->get('viewer_country'),
]);

Twig 函数: curator_render_promotion

使用具有 triniti:curator:mixin:render-promotion-request 混合的请求渲染推广。响应(具有 triniti:curator:mixin:render-promotion-response 混合)包含一个 widgets 字段,它是一个包含 triniti:curator:mixin:render-widget-response 消息的数组。将这些消息中的所有 html 字段汇总到一个字符串中,并由 twig 渲染。

参数

  • string $slot
  • RenderContext|array $context = []
  • bool $returnResponse = false 当您想要原始渲染响应时使用。

示例

# page.html.twig

{{ curator_render_promotion('smartphone-home-sidebar', {
  section: 'permalink',
  booleans: {
    enable_ads: true,
    dnt: false,
    autoplay_videos: false,
  },
  strings: {
    custom1: 'val1',
    custom2: 'val2',
    customN: 'val3',
  },
}) }}

</body>
</html>

Twig 函数: curator_render_promotion_slots

渲染促销的槽位与curator_render_promotion非常相似,但在这个情况下,你已经知道了促销,并告诉twig渲染所有slots,这些是triniti:curator::slot实例。所有匹配渲染上下文promotion_slot值的槽位都将被渲染。

使用triniti:curator::slot允许你在服务器、客户端和延迟情况下渲染不同的代码。请参阅triniti:curator:slot-rendering枚举。

参数

  • 消息|节点引用|string $promotionOrRef
  • 渲染上下文|array $context
  • bool $returnResponse = false 当您想要原始渲染响应时使用。

示例

# page.html.twig

{{ curator_render_promotion_slots('acme:promotion:4a0a55f2-c6ac-4044-bcc0-cb7e47be2509', {
  promotion_slot: 'jumbotron-top',
  section: 'jumbotron',
  booleans: {
    enable_ads: true,
    dnt: false,
    autoplay_videos: false,
  },
  strings: {
    custom1: 'val1',
    custom2: 'val2',
    customN: 'val3',
  },
}) }}

</body>
</html>