I'm looking for a solution that shows the canonical meta tag only when a page is set to 'index' in the meta tag robots.
Just to clarify things: I use 'robots' = 'index' or 'noindex' on every page as a meta tag to instruct search engines. However since it's SEO best practice, I only want to show the canonical meta tag when a 'robots' meta tag is available on the page AND contains the value 'index'.
you did not specify how you doing this (I will use select field in blueprint with 4 options index, follow / index, nofollow / noindex, follow / noindex, nofollow ) and set something like:
Many thanks for your help. This makes total sense. But since I'm new to Grav (which seems to be the reason...) I can't get a blueprint to work... It drives me nuts. I use the template resume: https://github.com/getgrav/grav-theme-resume
On top of that I have a multi language page, so my user/pages folder looks like this:
left (folder)
resume.de.md
resume.en.md personal statement (folder)
default.de.md
default.en.md languages (folder)
languages.de.md
languages.en.md
In the users/themes/resume/blueprints folder I have a resume.de.yaml file but it won't change anything in the backend (at least I can't find any changes). I even copied the first example code from here, just to make sure that it would work: https://learn.getgrav.org/17/forms/blueprints/example-page-blueprint
PS: I also created a left folder in the blueprints folder and added a resume.de.yaml file in there but that wouldn't change anything either.
PS 2: The left folder is the homepage if you will.
I have a resume.de.yaml file but it won’t change anything [..]
Don't use language extensions like .de.yaml to blueprints.
The field's label and help properties will automatically be translated when using a proper language.yaml* file.
I use ‘robots’ = ‘index’ or ‘noindex’ on every page as a meta tag
Do you mean the following inside the header (aka. frontmatter) of the page?
YAML
metadata:robots:index
If so, I also presume you are using field 'Metadata' in Admin on tab 'Options'. In that case, there is no need for a blueprint.
Considering my presumptions the following should work:
Override Resume's template templates/partials/base.html.twig by following the instructions in Extend base template of inherited theme.
Replace the onTwigLoader function with: