Page.content strangeness in modular pages and modular hero

I’d like to be able to access the text content of my modular hero page in another module, and I’m running into trouble.

I’ve noticed that page.find('/a_page')content in normal pages returns the HTML version of the page markdown, but in modular pages, page.find('/home/_a_module').content also returns the surrounding HTML structure of the module (<section>, <div>, etc). First question is: Is there any way to access only the text content without the surrounding HTML?

More importantly for my problem: Beyond that (in Quark), when I use page.find('/home/_hero').content, it only returns the surrounding HTML. It does not return any of the text content in ‘hero.md’:

<section id="" class="section modular-hero hero" style="background-image: url('/user/pages/01.home/01._hero/hero_img.jpg');">
<div class="image-overlay"></div>
<section class="container grid-xl" style="text-align: center">
</section>
<i id="to-start" class="pulse fa fa-angle-down"></i>
</section>

(In the actual rendered HTML on the site, of course, the hero text is right inside the inner <section>...</section> tags. But page.find('/home/_hero').content does not return the hero text.

My second and more important question then is: How can I access the text content from hero.md? (And why is the page.find().content behaving differently with the hero module than with other modules?)

The only thing I can think of is that it may have something to do with Quark’s modular/hero.html.twig has {% include 'partials/hero.html.twig' %}, and partials/hero.html.twig specifies the html for the section, and within that, {{ content|markdown }}

Any help or insight would be greatly appreciated!

Answers provided by some very helpful folks on discord:

  1. page.content returning the structuring HTML is expected behavior on modules.
  2. To access the markdown content of the hero.md, page.rawMarkdown works.
1 Like