Skip to content

Entry types title format preview CKEditor field. #15885

Closed Answered by brandonkelly
thomascoppein asked this question in Q&A
Discussion options

You must be logged in to vote

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 _includes/extract-h1.twig template in your templates/ folder, with this code:

{% set crawler = create(
  'Symfony\\Component\\DomCrawler\\Crawler',
  [object.myCkeditorField.getParsedContent() ?? '']
) %}

{% set h1 = crawler.filter('h1') %}

{{ h1|length ? h1.html() : "Entry #{object.id}" }}

(Replace myCkeditorField with the actual CKEditor field handle.)

And finally, set your entry type’s Title Format to:

{% include '_includes/extract-h1.twig' %}

Your existing entries sh…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants