Entry types title format preview CKEditor field. #15885
-
Hi, For example, given the following CKEditor content: I want the title to be: Issues I’m facing:
Is there a way to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can do that using Symfony’s DomCrawler + CssSelector components. Run the following CLI command from your project root: composer require symfony/dom-crawler:"^6.0|^7.0" symfony/css-selector:"^6.0|^7.0" Then create an {% set crawler = create(
'Symfony\\Component\\DomCrawler\\Crawler',
[object.myCkeditorField.getParsedContent() ?? '']
) %}
{% set h1 = crawler.filter('h1') %}
{{ h1|length ? h1.html() : "Entry #{object.id}" }} (Replace And finally, set your entry type’s Title Format to: {% include '_includes/extract-h1.twig' %} Your existing entries should be resaved automatically via a queue job, and then their titles will be updated with the contents of the first |
Beta Was this translation helpful? Give feedback.
You can do that using Symfony’s DomCrawler + CssSelector components.
Run the following CLI command from your project root:
Then create an
_includes/extract-h1.twig
template in yourtemplates/
folder, with this code:(Replace
myCkeditorField
with the actual CKEditor field handle.)And finally, set your entry type’s Title Format to:
Your existing entries sh…