Skip to content

Latest commit

 

History

History
94 lines (65 loc) · 1.69 KB

editor.md

File metadata and controls

94 lines (65 loc) · 1.69 KB

Editor Extension

Sometimes you have very special styling for ul, ol lists or other tags which are used in a text editor where you are not able to add class. This twig extension should help you to wrap that output in a div or add classes to it.

Setup

Service Registration

The editor extension need to be registered as symfony service.

services:
    Sulu\Twig\Extensions\EditorExtension: ~

    # Full configuration:
    Sulu\Twig\Extensions\EditorExtension:
        arguments:
            - { ul: 'list' }
            - 'div'
            - 'editor'

If autoconfigure is not active you need to tag it with twig.extension.

Usage 'editor_classes' filter

Basic Usage

{% set yourHtml = '<ul><li>Test</li></ul>' %}
{{ yourHtml|editor_classes }}

This will output:

<ul class="list"><li>Test</li></ul>

Specify classes

{% set yourHtml = '<ul><li>Test</li></ul>' %}
{{ yourHtml|editor_classes({ul: 'special-list'}) }}

This will output:

<ul class="special-list"><li>Test</li></ul>

Usage editor filter

Basic Usage

{% set yourHtml = '<p>Test</p>' %}
{{ yourHtml|editor }}

This will output:

<div class="editor"><p>Test</p></div>

Custom Tag

{% set yourHtml = '<p>Test</p>' %}
{{ yourHtml|editor('section') }}

This will output:

<section class="editor"><p>Test</p></section>

Custom Class

{% set yourHtml = '<p>Test</p>' %}
{{ yourHtml|editor(null, 'custom') }}

This will output:

<div class="custom"><p>Test</p></div>