1

I am rendering some headings using twig and want to know if there is a better and more readable way of doing the following...

<{{ block.headingType }} class="measure-wide">{{ block.headingText }}</{{ block.headingType }}>

{{ block.headingType }} is the value of the heading selected in the editor. The values are h2, h3, h4, h5 etc.

The way the HTML headings are templated looks ugly (even though the rendering works). Is there a better way of rendering out the heading tags in twig based on the value selected?

1 Answer 1

3

Is there any reason you dont use a rich text field like redactor? You can make a custom config so that field only has h1,2,3 and no links, lists etc.

And instead of having the class "measure-wide" on the heading element you can wrap it.

Something like {{ block.heading }} Where block.heading is a custom redactor field.

1
  • That is a very good point. Lateral thinking at its best.
    – Dan Lee
    Dec 4, 2018 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.