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

How to hide page-toc table of contents on a blog card?

first-time plugins

Started by Jean 5 years ago · 1 replies · 751 views
5 years ago

Hello !
First of all, thank you to all the community for Grav. I've never created a website before, but the more I dig and the more I like this CMS ! 😍

So, I'm stucked and cant't find the solution to this. Hope you will understand :upside_down_face:

I use the page-toc plugin to have a table of contents just under the title and the content of my blog items (I have tried the Anchor plugin without success, I'm certainly too new to code)

Here is the part of my blog_item.html.twig

TWIG
<header class="entry-header">
    <h1 class="entry-title">
        ...
    </h1>
    {% if config.get('plugins.page-toc.active') or attribute(page.header, 'page-toc').active %}
        <div class="page-toc">
            {% set table_of_contents = toc(page.content, 2, 1) %}
            {% if table_of_contents is not empty %}
                <h4>Sommaire</h4>
                {{ table_of_contents|raw }}
            {% endif %}
        </div>
    {% endif %}

</header>

<div class="entry-content">
...
</div>

On my blog page i have some rows who show the blog items extracts (I'm using the Gateway template) and would like to display only the entry-title and the entry-content.

TWIG
{% block content %}
<div class="row">
  <div id="primary" class="content-area">
       <div class="large-{% if not page.header.fullwidth %}8{% else %}12{% endif %} columns">
      <main id="main" class="site-main" role="main">
        {% for child in collection %}
        <div class="row">
          {% include 'partials/blog_item.html.twig' with {'page':child, 'truncate':true} %}
        </div>
        {% endfor %}
        {% if config.plugins.pagination.enabled and collection.params.pagination %}
        {% include 'partials/pagination.html.twig' with {'base_url': page.url, 'pagination':collection.params.pagination} %}
        {% endif %}
      </main>
    </div>
        ...
    </div>
</div>
{% endblock %}

Have i to modify something on the include function ?

Thank you !

5 years ago

I think I found it...

On the blog_item.html.twig, I have placed the page-toc code on a div under the header, with the condition {% if truncate is sameas(false) %} as bellow :

TWIG
<div>
        {% if truncate is sameas(false) %}
            {% if config.get('plugins.page-toc.active') or attribute(page.header, 'page-toc').active %}
                <div class="page-toc">
                    {% set table_of_contents = toc(page.content, 2, 1) %}
                    {% if table_of_contents is not empty %}
                        <h4>Sommaire</h4>
                        {{ table_of_contents|raw }}
                    {% endif %}
                </div>
            {% endif %}
        {% endif %}
    </div>

It seems to work, I hope I didn’t do anything wrong :upside_down_face:

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 80 1 week ago
Plugins · by Xavier, 4 weeks ago
2 84 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1210 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 77 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 103 2 months ago