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.

Content & Markdown

Delimiter doing the opposite

Started by Leonardo 1 year ago · 3 replies · 58 views
1 year ago

Hi there, sorry if this is not the right category, I am building a blog from scratch and my summary is doing the reverse of what it should be doing: Ignoring the summary before the delimiter and truncating the text that comes after. Thanks in advance.

This is my blog_item.html.twig

TWIG
{% if truncate %}
    <div class="list-item home-card grower">
        {# CARD image #}
        <div class="header-image-wrapper">
            <a href="{{ page.url }}" class="u-url">
            {% if header_image %}
                {% if header_image_file %}
                    {% set header_image_media = page.media.images[header_image_file] %}
                {% else %}
                    {% set header_image_media = page.media.images|first %}
                {% endif %}
                {{ header_image_media.cropZoom(header_image_width, header_image_height).html|raw }}
            {% endif %}
            </a>
        </div>

        <div class="padded-sides-sm">
            {# TAGS #}
            {% include 'partials/taxonomy.html.twig' %}

            {# DATE (COND) #}
            {% if page.date.tag %}
                <span class="list-blog-date">
                    <time class="dt-published" datetime="{{ page.date|date("c") }}">
                        <span>{{ page.date|date("d") }}</span>
                        <em>{{ page.date|date("M") }}</em>
                    </time>
                </span>
                <br>
            {% endif %}

            {# TITLE CARD #}
            <a href="{{ page.url }}" class="u-url">
                <h2 class="p-name">{{ page.title }}</h2>

                {# Truncated content #}
                <div class="p-summary">
                    {{ page.summary|raw }}
                </div>
            </a>
        </div>
    </div>

{#  FULL POST (DISPLAYED WHEN 'truncate' IS FALSE)  #}
{% else %}
    <div class="blog-content">
        {# DATE (COND) #}
        {% if page.date.tag %}
            <span class="list-blog-date">
                <time class="dt-published" datetime="{{ page.date|date("c") }}">
                    <span>{{ page.date|date("d") }}</span>
                    <em>{{ page.date|date("M") }}</em>
                </time>
            </span>
            <br>
        {% endif %}

        <div class="case-study">
            {# CASE STUDIES #}
            {% include 'partials/prevnext.html.twig' %}
            {% include 'partials/taxonomy.html.twig' %}
            <div id="text-wrapper">
                <section id="caption-section">
                    <h3>{% for category in page.taxonomy.category %}{{ category }}{% endfor %}</h3>
                    <h1>{{ page.header.title|e }}</h1>
                </section>
                {{ page.content|raw }}
            </div>
            {% include 'partials/prevnext.html.twig' %}
        </div>
    </div>
{% endif %}

1 year ago

@lonko, A kind request to be kind to the reader's time and effort.

TLDR:

  • Only present a relevant code snippet that replicates the issue.
  • Show what the markdown of the page looks like.
  • Show what is being displayed in the page.
  • And update your post accordingly.

Long read: /forum/general/the-art-of-asking-great-questions-t8554

Thank you.

1 year ago

@pamtbaau:

  • e markdown of the page looks like.
  • Show what is being displayed in the pa

I thought of shortening the code sample but I thought it might need more context, like people could rightly think I botcheded the Ifs and elses (which I am known to do). Also added comments.

The markdown page is pretty straighforward:

TXT
This text is a summary and should be displayed on the homepage, but isn't.

===

This text is the beginning of the post, shouldn't be displayed on the homepage, but it is, then truncated.

Thank you

last edited 03/04/25 by Leonardo
1 year ago

Still not enough info. Where does truncate come from?

If it's doing the opposite of what's expected, did you try replacing {% if truncate %} with {% if not truncate %}?

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 93 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 184 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 145 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 253 1 year ago
Content & Markdown · by David Schad, 2 years ago
2 58 2 years ago