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

How to add custom html in head only on particular page

Solved by Iusew View solution

Started by Iusew 5 years ago · 6 replies · 2227 views
5 years ago

I want to add Schema Tags for each page like FAQPAGE and QAPage Tags and others so I want to add some content to head but only on that page, I searched everywhere no plugin or method available.

5 years ago

In your page template you could have something like

TWIG
{% extends 'partials/base.html.twig' %}

{% block head %}
    {{ parent() }}
    <any custom="tag" />
{% endblock %}
5 years ago

Where to add this bit of code?? I am super sorry for such a bad question but I am beginner so I don't know 😅

5 years ago

What steps did you take to achieve your goal? Are you familiar with templates? If not, did you read the docs? When you have understanding how page templates in Grav work, then you might provide us with more information needed, because now (at least) I have no answer without knowing anything about your page structure.

👍 1
5 years ago Solution

I got a solution myself after 24 hours hard work and reading docs, So If someone is also trying to achieve the same then here is the step by step solution:

Configuration :

  1. Open this file in editor user\themes\themename\templates\partials\base.html.twig
  2. Add this a bit of code before ending head tag {{ header.customhtml|raw }}

Usage :

  1. If you are using admin plugin then simple select Expert Mode in page and you will see a title : ' title here' this type of text all you need to do is leave one line and enter your custom html like below line!
    customhtml : '<anything in html you want></aihyw>'

Now If you want you can go back to normal and save page and see the page source you will see that you are successful.

  1. If you are not using admin panel then all you need to do is add this line in the markdown file in the column where the title is present.
    customhtml : '<anything in html you want></aihyw>'
5 years ago

If you are using one of the installed themes from GPM, you will loose {{ header.customhtml|raw }} part on update. You should either extend a theme or have your own.

5 years ago

Yes I am using my custom theme!

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 94 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 146 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 60 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 254 1 year ago