I am currently building a doc system with multiple levels. I have build individual entries, but I'd like to parse the whole documentation in one page. Currently, I'm doing it like this:

{% set pages = craft.entries()

{% for page in pages %}

  {{ page.articleContent }}

    {% if page.hasDescendants %}

      {% set children = page.children.all() %}

      {% for child in children %}

        {{ child.articleContent }}

      {% endfor %}

    {% endif %}

{% endfor %}

Though, with Redactor, all h2 defined in deeper levels remain h2. Is there a way to detect if an entry is at level 2 or 3 and set all the headings to n-level?

Thanks! :)


You could potentially use Twig's replace filter to replace any instance of h2 with h3. If for some reason that's not powerful enough, there's also the Retcon plugin which could work too - specifically the change method: https://github.com/mmikkel/Retcon-Craft/wiki/Change

  • Hey James, thanks for the comment. I was trying something with replace filter. I couldn't get something conclusive (yet). I will dig a bit further in that direction. In the meantime, I'll check the Retcon plugin :)
    – katsele
    Jul 7 '21 at 11:57
  • Hey James, I did some tests with this solution, it seems that replace filter returns a string. So I tried to wrap the content in a {% html %} tag. Unfortunately, with this tag, nothing shows up in the rendered page. Ever faced something like this?
    – katsele
    Jul 20 '21 at 17:14
  • Try using the raw filter Jul 22 '21 at 8:21
  • It worked! Thank you so so much :)
    – katsele
    Jul 22 '21 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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