Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Page.content strangeness in modular pages and modular hero

Solved by paul View solution

Started by paul 6 years ago · 1 replies · 501 views
6 years ago

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':

HTML
<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!

last edited 03/14/20 by paul
6 years ago Solution

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

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 93 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago