Skip to content

Commit

Permalink
add a rich text component
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vo committed Mar 20, 2024
1 parent 7c69ccb commit eda2789
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
34 changes: 34 additions & 0 deletions core-bundle/contao/templates/twig/component/_rich_text.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{#
This component outputs rich text content, that was typically composed by
an editor in the backend using the tinyMCE editor.
<div class="rte">
<p>Lorem ipsum</p>
</div>
Mandatory variables:
@var string text
Optional variables:
@var \Contao\CoreBundle\String\HtmlAttributes attributes
Note:
You can either group all variables in an object named "rich_text" or
all directly in the context. Grouping under an object has precedence.
#}

{% trans_default_domain "contao_default" %}

{% block rich_text_component %}
{% set rich_text = rich_text|default(_context) %}

{% set rich_text_attributes = attrs(rich_text.attributes|default)
.addClass('rte')
.mergeWith(rich_text_attributes|default)
%}
<div{% block rich_text_attributes %}{{ rich_text_attributes }}{% endblock %}>
{% block rich_text_inner %}
{{ rich_text.text|csp_inline_styles|insert_tag|encode_email|raw }}
{% endblock %}
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "@Contao/content_element/_base.html.twig" %}
{% use "@Contao/component/_figure.html.twig" %}
{% use "@Contao/component/_rich_text.html.twig" %}

{% set content_layout_attributes = attrs()
.addClass('media media--' ~ layout, layout and image)
Expand All @@ -22,12 +23,6 @@

{# Richtext #}
{% block text %}
{% set text_attributes = attrs()
.addClass('rte')
.mergeWith(text_attributes|default)
%}
<div{% block text_attributes %}{{ text_attributes }}{% endblock %}>
{{ text|csp_inline_styles|insert_tag|encode_email|raw }}
</div>
{% with {text, attributes: text_attributes|default} %}{{ block('rich_text_component') }}{% endwith %}
{% endblock %}
{% endblock %}

0 comments on commit eda2789

Please sign in to comment.