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

Theme variable for content without title?

Started by colin avolve 3 years ago · 12 replies · 864 views
3 years ago

To display a pages content, the following theme variable is including in a template

TWIG
{{ content|raw }}

Which includes the title and be body of text

You can also display just the title using

TWIG
{{ header.title|raw }}

Is there a way to display just the body of text, without the title?

I have re-read the docs. Also a few searches here and I have either missed this, or didn't find it.

thx

last edited 02/22/23 by colin avolve
3 years ago

{{ content }} includes the page title and body of text (text below the line in the md file) I have updated the OP to clarify this.

3 years ago

@avolve, just use

TWIG
{{ page.title|e }}
{{ page.content|raw }}

i assume you have something similar in your code

TWIG
{% set content %}
    <h1>{{ page.title|e }}</h1>
    {{ page.content|raw }}
{% endset %}

and then
{{ content|raw }}

3 years ago

thanks @b.da

To clarify further, this is a modular page/template, Quark theme inheritance. And

TWIG
{{ content|raw }}

and

TWIG
{{ page.content|raw }}

generate the same output, including the title and body text.

Any tips own how/where I can set/reset page.content?

3 years ago
  1. clear the cache when you make changes to a modular template
  2. you need to be more specific, and share modular (if it modified) + module page file .md and template .html.twig (if we are talking about the module itself), so the community can help
3 years ago

Not sure what to suggest here.. I have this in my modular templates and it doesn't show title:

TWIG
    <div>
        {% if page.header.show_title %}
            <h3>{{ page.title }}</h3>
        {% endif %}
        {{ content|raw }}
    </div>

I'm pretty sure you have a title in your main content. Something like:

YAML
---
some: header stuff
---

# Your title

And content
3 years ago

Appreciate the further suggestions.

The header for the md file includes

YAML
---
title: Leagues and Divisions
routable: false
menu: Teams
---

and the template.html.twig

TWIG

{% set grid_size = theme_var('grid-size') %}

<section class="section modular-cards {{ page.header.class}} bg-gray">
    <section class="container {{ grid_size }} grid-lg">
      <div class="column col-12">
          {{ content|raw }}
      </div>
    </section>
</section>

As there is a title in the header,

TWIG
{{ page.title|e }}

Will reproduce the title (as wanted). However

TWIG
{{ content|raw }}

Produces both the title and body content. When I want to separate out the body content.

(I am adding some more fields to the template, and want to place the title above these, and body content below)

3 years ago

@avolve, You keep repeating that variable content contains the body and title of the page, while others claim it doesn't, which I agree with.

{{ content|raw }} does not output the value of {{ page.header.title }}

Would you mind providing us some proof for your claim?

  • Please download the One-Page Site skeleton, which is a plain Quark based site containing a single modular page.
    The modular itself and each of its modules have a title set in the frontmatter/header of the file.
  • Could you show us where the title from the header of the modular page, or any of its modules, appears in the output (the generated HTML) of the page?

The only title I can find in the generated HTML is the title of the modular.md which appears in the <head> of the page.

last edited 02/24/23 by pamtbaau
3 years ago

I do appreciate the assistance (though your tone reads as passive aggressive and infers I am lying — which is not helpful).

Marking this as closed.

3 years ago

@avolve, I'm sorry you perceive my reply as passive aggressive. It certainly wasn't intended that way.

I also don't believe that you are lying. I do believe you are seeing something happening on your site that leads to the impression that {{ content }} contains the title.

Maybe me not being a native speaker made me use a sensitive tone of voice.

In an attempt to resolve the looping yes/no discussion, I wanted to go back to a default repeatable configuration to establish that {{ content | raw }} does, or does not, print the title from the header. After getting the yes/no out of the way, we can progress and help you getting the result you're trying to implement.

👍 2
last edited 02/24/23 by pamtbaau
3 years ago

@avolve:
The header for the md file includes

YAML
---
title: Leagues and Divisions
routable: false
menu: Teams
---

@avolve:
your tone reads as passive aggressive and infers I am lying

Well.. You're definitely not telling a full story here. You say your MD has only header without body, but you see title AND the body in your content. You never provided how the body of your MD looks. Based on the resolution of the topic, I assume there was a # Title in your MD body

👍 1
3 years ago

@avolve, Despite the direction into which the discussion went, I'm curious if you found a solution to the issue. Would you mind sharing it?

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 196 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 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 126 3 months ago