Since Drupal 8 renders HTML with tons of its twig templates, it's always painful to make HTML structure to be what you want, then QueryPath is super useful for this.
- Enable this
- Check the examples in src/TwigExtension.php, then create your own helper functions there.
- You can do this in any twig templates:
{% set ct = page.content %}
{{ your_helper_function_in_module(ct) }}