Longform Content with CKEditor - separate field contents into "text blocks" and "entries blocks" so we can loop through them #238
-
Although this is related to ckeditor which has separate repository, i feel that ckeditor is such integral part of craft development that this discussion could be started there. The problem: Even if we include entries partials into ckeditor field, all that is returned by the field in the template is just a markup. This can cause some complications when trying to build layouts. Another problem would be if we use something like tailwind Proposed solution: Add some method to the ckeditor field that would return array - each position would be either text "block" or "block" containing the partial component html. Developer could just loop through them and decide what to put into the container class. This is how it works with Vizy plugin. Hacky solution: For now i have managed to solve this problem using Retcon plugin.
In this example, i just wrap every first level html tag returned by ckeditor in div that has "container" class. I exclude |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 20 replies
-
Another way you could achieve that would be to wrap the entire contents in a container, and then have each partial template close the container first, and open a new one after outputting its partial content. You could even have it based on a custom {% if entry.myCkeField|length %}
{% set content %}
{% set breakContainers = _globals.get('breakContainers') ?? false %}
{% do _globals.set('breakContainers', true) %}
<div class="container">
{{ entry.myCkeField }}
</div>
{% do _globals.set('breakContainers', breakContainers) %}
{% endset %}
{# output the contents, but with empty container divs removed #}
{{ content|retconRemoveEmpty('div') }}
{% endif %} Then from your partial templates: {% if _globals.get('breakContainers') %}
</div>
{% endif %}
... partial content ...
{% if _globals.get('breakContainers') %}
<div class="container">
{% endif %} |
Beta Was this translation helpful? Give feedback.
-
As for the layout part, there are ways to achieve what you describe with css grid. One way to go about it is detailed here. Though I definitely support your FR since it would allow more fine tuned control of the output. |
Beta Was this translation helpful? Give feedback.
-
For me what I really wanted from Craft was something like the Bard field in Statamic or Kirbys Block field i.e. a Matrix like API but a streamlined interface which gives the best of both worlds. I thought originally that was the plan for Craft with the talk of the use of something like TipTap and structured data. The update to CKEditor is nice and can get you out of a hole but I don't think it's a complete solution. Hopefully something like Bard/Blocks is still on the cards 🤞 |
Beta Was this translation helpful? Give feedback.
-
Making this possible for CKEditor 4.1 (#241). |
Beta Was this translation helpful? Give feedback.
Making this possible for CKEditor 4.1 (#241).