connectholland/sulu-block-bundle

一个用于Sulu内容管理平台的Symfony Bundle,包含样板块

2.2.1 2023-05-09 13:22 UTC

README

一个用于Sulu内容管理平台的Symfony Bundle,包含样板块

1. 安装

Composer

composer require connectholland/sulu-block-bundle

2. 使用方法

模板

添加或调整页面模板文件(请注意添加 xmlns:xi="http://www.w3.org/2001/XInclude")

<!-- app/Resources/templates/pages/default.xml -->
<?xml version="1.0" ?>
<template xmlns="http://schemas.sulu.io/template/template"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xi="http://www.w3.org/2001/XInclude"
          xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd">

    <key>default</key>

    <view>templates/default</view>
    <controller>SuluWebsiteBundle:Default:index</controller>
    <cacheLifetime>2400</cacheLifetime>

    <meta>
        <title lang="en">Default</title>
        <title lang="nl">Standaard</title>
    </meta>

    <properties>
        <!--
        <section name="highlight">
            <properties>
                <property name="title" type="text_line" mandatory="true">
                    <meta>
                        <title lang="en">Title</title>
                        <title lang="nl">Titel</title>
                    </meta>
                    <params>
                        <param name="headline" value="true"/>
                    </params>

                    <tag name="sulu.rlp.part"/>
                </property>

                <property name="url" type="resource_locator" mandatory="true">
                    <meta>
                        <title lang="en">Resourcelocator</title>
                        <title lang="nl">Adres</title>
                    </meta>

                    <tag name="sulu.rlp"/>
                </property>
            </properties>
        </section>

        <property name="article" type="text_editor">
            <meta>
                <title lang="en">Article</title>
                <title lang="de">Artikel</title>
            </meta>
        </property>-->

        <!-- Choose the same name as using in twig (see next paragraph) -->
        <block name="blocks" default-type="text" minOccurs="0">
            <meta>
                <title lang="en">Content</title>
                <title lang="nl">Inhoud</title>
            </meta>
            <types>
                <xi:include href="sulu-block-bundle://blocks/text.xml"/>
                <xi:include href="sulu-block-bundle://blocks/youtube.xml"/>
            </types>
        </block>

        <!-- Choose the same name as using in twig (see next paragraph) -->
        <block name="banners" default-type="text" minOccurs="0">
            <meta>
                <title lang="en">Banners</title>
                <title lang="nl">Banners</title>
            </meta>
            <types>
                <xi:include href="sulu-block-bundle://blocks/text.xml"/>
                <xi:include href="sulu-block-bundle://blocks/youtube.xml"/>
            </types>
        </block>
    </properties>
</template>

Twig

向您的twig模板中添加包含

{% block content %}
    <div vocab='http://schema.org/' typeof='Content'>
        <h1 property='title'>{{ content.title }}</h1>

        <div property='article'>
            {{ content.article|raw }}
        </div>

        {% include '@ConnectHollandSuluBlock/html5-blocks.html.twig' %}
        {% include '@ConnectHollandSuluBlock/html5-blocks.html.twig' with {element: 'aside', collection: 'banners'} %}
    </div>
{% endblock %}

覆盖twig模板

将具有与您想要覆盖的模板相同名称的twig模板放在templates/bundles/ConnectHollandSuluBlockBundle中。因此,如果您想覆盖此包中的src/Resources/views/html5/parts/images.html.twig,则应在您的客户端应用程序中创建以下文件:

如果您只想覆盖此包中模板的某些块,您可以通过使用命名空间@!ConnectHollandSuluBlock来扩展基本模板。

例如

{# templates/bundles/ConnectHollandSuluBlockBundle/html5/parts/images.html.twig #}
{% extends "@!ConnectHollandSuluBlock/html5/parts/images.html.twig" %}

{% block image_source %}{{ image.thumbnails['50x50'] }}{% endblock %}

3. 可用块

  • 带有标题的文本(text)
  • 带有标题的图片(images)
  • 带有标题和文本的图片(images_text)
  • 带有标题的YouTube视频(youtube)
  • 带有标题的链接(link)

4. 添加附加属性

当使用一个块并且想要添加附加属性时,您可以在config/templates/ConnectHollandSuluBlockBundle/properties/{blockname}.xml中单独配置它们。例如,如果您想为图片块添加一个说明。您应该在您的客户端应用程序中创建以下文件

<!-- config/templates/ConnectHollandSuluBlockBundle/properties/images.xml -->
<?xml version='1.0' ?>
<properties xmlns='http://schemas.sulu.io/template/template'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd'
    >
    <property name='caption' type='text_line'>
        <meta>
            <title lang='en'>Caption</title>
            <title lang='nl'>Bijschrift</title>
        </meta>
    </property>
</properties>

5. 覆盖属性参数

5.1 完全覆盖所有参数

当使用一个块并且想自己选择块属性的参数时,您可以在config/templates/ConnectHollandSuluBlockBundle/params/{blockname}.xml中单独配置它们。例如,如果您想为文本编辑器属性设置所有参数。您应该在您的客户端应用程序中创建以下文件

<!-- config/templates/ConnectHollandSuluBlockBundle/params/text_editor.xml -->
<?xml version='1.0' ?>
<params xmlns='http://schemas.sulu.io/template/template'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd'
    >
    <param name="link" value="true"/>
    <param name="paste_from_word" value="true"/>
    <param name="height" value="100"/>
    <param name="max_height" value="200"/>
</params>

5.2 调整参数

当使用一个块并且想更改块属性的参数时,您可以在config/templates/ConnectHollandSuluBlockBundle/params/{blockname}_adjustments.xml中单独配置它们。例如,如果您想调整文本编辑器属性的高度并禁用表格功能。您应该在您的客户端应用程序中创建以下文件

<!-- config/templates/ConnectHollandSuluBlockBundle/params/text_editor_adjustments.xml -->
<?xml version='1.0' ?>
<params xmlns='http://schemas.sulu.io/template/template'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd'
    >
    <param name="height" value="200"/>
    <param name="table" value="false"/>
</params>

5.3 添加参数

当使用一个块并且想向块属性添加参数时,您可以在config/templates/ConnectHollandSuluBlockBundle/params/{blockname}_additions.xml中单独配置它们。例如,如果您想向文本编辑器属性添加ui_color参数。您应该在您的客户端应用程序中创建以下文件

<!-- config/templates/ConnectHollandSuluBlockBundle/params/text_editor_additions.xml -->
<?xml version='1.0' ?>
<params xmlns='http://schemas.sulu.io/template/template'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd'
    >
    <param name="ui_color" value="#ffcc00"/>
</params>