Twig in Quark to Insert Ad Script to All Pages

I’ve read the docs re. twigs as well as looking at the default Quark theme’s file system.

(I looked for where ‘frontmatter’ is auto-generated for each page (parent or child) but had trouble finding a doc for that.)

Are these instructions from 2017 still best practice for inserting an ad script into the theme - so that it repeats on every parent and child page? https://discourse.getgrav.org/t/adsense-script-in-grav-content/2736

NOTE1: I’m using yllix ads, not google.

NOTE2: The script is “text/javascript”.

Thanks.

Doesn’t look like a good solution. I’d rather extend the theme and insert the script to base template(s)

Thanks!

I found this thread …
https://discourse.getgrav.org/t/included-grav-logo-svg-missing-on-extending-theme/5413/5

Then visited here …
https://github.com/getgrav/grav-theme-quark/blob/develop/quark.php

Where rhuk wrote: “… use Devtools plugin to create a new ‘inherited’ theme. It does most of the work for you.”

I read …
https://github.com/getgrav/grav-plugin-devtools/blob/master/README.md

So, do I create a new theme (a copy of Quark with a different name), then paste my yllix ad script in at line 20 of ~/quark.php (the “public function” section)?

@nginxgrav, Please read the docs to get to know the basic concepts of Grav. Looking at your questions, the lack of insight hinders you from progressing. It also leads to more load on the community.

The community is very much willing to help, but we appreciate it when a user shows self provisioning by:

  • Doing research:
    1. Firstly, by doing research on the topic in the docs, which provides a central place for all concepts.
    2. Searching Github (Grav, theme. plugin) to find out if issue is already a known issue.
    3. Searching this forum for similar issue.
  • Show what has been tried and where one got stuck.
    • Show well formatted (using triple backticks) code snippets (no screenshots) if helpful
    • What is expected to happen.
    • What does happen instead.

To give a few hints about adding js/css scripts/libraries:

I’m really trying to do the best I can to learn and apply. I’m not a developer/programmer, I’m an end user. (I tried to show that I had done 1, 2, & 3. I’m also 68 and don’t learn quite as quickly as I used to.)

Thanks for the additional links.

OK re. “inheriting” vs “copying” - they sound very similar to me so I’ll have to parse that some before the difference is clear enough to me.

Grav has been developed with developers in mind. Admin has been added later as an add-on, to facilitate editing pages and simple config changes by less skilled users. If a user requires more changes than provided by Admin and theme, a basic set of skill and conceptual knowledge will be required.

Tools like Wix (and other drag&drop website builders) or Wordpress.com are much more accessible to end-users who wish to build websites.

I plan to go far beyond a Web site but chose to start relatively simply.
I have started just pasting the ad script into each page but saw a learning opportunity in discovering how to automate that process in the theme.
8,700 people in our university town will now become aware of grav. Some will be developers in the GSU computer and engineering program.

At this point all I can suggest, is to make your own theme by inheriting Quark. I advice CLI to do this. Then read a Cookbook recipe how to extend base template. When you get to the point where your inherited theme works with your extended base template, I believe you will know how to add the script

1 Like

I never even noticed the “Cookbook” area. That’s awesome! Thanks!