Included grav-logo.svg missing on extending theme

Hi there,
i just started with grav - and hope my questions are not too stupid to be answered.

I startet with a new theme extending the default quark theme.

everything works fine except the include of the grav-logo.svg.
this ist included in the base.html.twig as :

{% include('@images/grav-logo.svg') %}

if i activate the new theme i got a runtime exception :
Template “@images/grav-logo.svg” is not defined in “partials/base.html.twig”

the logo is available at both /images/ folder.
I am not sure, how this kind of include (@images/) really works.

could anyone give me a short hint - or even better an explanation on how to use this?

Thank you in advance
odde

The @images bit is actually a shorthand for a custom twig namespace that is defined in the quark.php file:

    // Add images to twig template paths to allow inclusion of SVG files
    public function onTwigLoader()
    {
        $this->grav['twig']->addPath(__DIR__ . '/images', 'images');
    }

I think perhaps I need to redefine this function to find a better way to get the current theme path.

Try replacing the quark.php function with this:

I think this:

    // Add images to twig template paths to allow inclusion of SVG files
    public function onTwigLoader()
    {
        $theme_path = Grav::instance()['locator']->findResource('theme://');
        $this->grav['twig']->addPath($theme_path . '/images', 'images');
    }

Should do the trick. (btw, you will probably also need to add use Grav\Common\Theme at the top too.

thank you very much for the help.

I changed the function in the origin quark.php and added the include instruction in the child’s theme base.html.twig again.

The error ist still the same.

the child’s php is still very slim and just looks like this:

 <?php
 namespace Grav\Theme;
 use Grav\Common\Theme;
 class Mytheme extends Quark
 {
    // Add images to twig template paths to allow inclusion of SVG files
 }
?>  

it doesn’t matter if the your provided function ist inserted here - and for my understanding it should be inherited from the parent theme anyway. … or am I wrong?

However - it is in fact more important to me to understand, what the problem ist, than to include the inherited logo.

Perhaps you could provide a link where i can find a more detailed description to this than i found on https://learn.getgrav.org/themes/ ?

Thank you in advance and your effort

best regards
odde

Ok, I hadn’t tested it, and I was on the right track, but needed a smidge more logic:

    // Add images to twig template paths to allow inclusion of SVG files
    public function onTwigLoader()
    {
        $theme_paths = Grav::instance()['locator']->findResources('theme://images');
        foreach(array_reverse($theme_paths) as $images_path) {
            $this->grav['twig']->addPath($images_path, 'images');
        }
    }

is the final method that gets all the theme paths (including inherited ones) and only includes paths that exist. However, for this to work in your inherited theme, you must extend the base theme:

<?php
namespace Grav\Theme;

use Grav\Common\Grav;
use Grav\Common\Theme;

class QuarkChild extends Quark
{

}

If you simply extend the Theme class, you would need to copy over the contents of the quark.php class to this one.

1 Like

oops - as i mentioned before, i am really a newbie on this.
first of all, thank you for your patience!

I am afraid, my mistakes startet even earlier.
In fact when i set up the child theme i did not name it in the childTheme.php - instead i litterally used the mytheme as name.

however, if i insert the name of the child in the php file, the site does not show anything but errors.
I thought, it worked with just this setup:

after disabling the grav-logo.png import anything behaved, as i expected and I was able to use any template or partial - if a *.html.twig was available in any of the template folders.

with the suggested changes built in , the site does not work at all - so i am afraid, i got most of the explanation on expanding themes wrong. Last not least when i did not gave the right theme name, the jschell.php did nothing at all - and i now wonder why and how this worked … but i will find out ^^

so i will first read the docu yet another time before wasting more of your time.

nevertheless - thank you once again for your time
… i am afraid i will be back very soon for further questions :wink:

best regards
odde

still confused …

just replayed the procedure to set up a childtheme following the doc at https://learn.getgrav.org/themes/customization

in any case - with or without the two use Grav\Common\Grav|Theme lines i get an error saying:

 Whoops \ Exception \ ErrorException (E_ERROR)
 Class 'Grav\Theme\Grav' not found

might there be anything else relevant that changed in the beta version not mentioned in the documentation ( for obvious reasons the doc is partially still on v0.9x)

for now i stick with this state i have, as it still does the mean parts of what i want, but it really would be nice to understand what’s going on.

that was the use Grav\Common\Grav; line i mentioned that needed to be added. See this: https://github.com/getgrav/grav-theme-quark/blob/develop/quark.php

BTW, in the future, use Devtools plugin to create a new ‘inherited’ theme. It does most of the work for you.

using the Devtools plugin leads to the same or similar errors - it works fine with any other theme i tried - so i suspect beside all mistakes i made, there could still be an issue with the theme.

for now i will stick with another theme and come back to quark later on because i really like it as a starting theme.

Thank you for all the help and hints

hi,
it’s me again :wink:

while trying to adapt my already written partials another Template i came across further mistakes i made:

  • the childTheme.php i posted closed with a ?>
  • i misunderstood your hint to copy the yaml. With adding the original settings on my childs.yaml things went really better

just wanted to let you know that i remorseful switched back to Quark and just replace the logo with my sites title.

Hi odde and rhuk! =)

I’m trying to make a child of the Quark theme but I also always run into a “RuntimeException (400) Template “@images/grav-logo.svg” is not defined”.

What I did is create a ‘myquark’ folder in ‘themes’ and /user/themes/myquark/myquark.yaml like showed in https://learn.getgrav.org/themes/customization (just with quark / myquark) and then changed user/config/system.yaml to the myquark theme.
=> Runtime Error

What did I do wrong?
Is there something special about the quark theme?
Shall I put more stuff into the myquark.yaml?

Thank you very much!
-Patrick-

@PatrickTT I did some test to find out the cause of above mentioned errors.

The steps I took:

  1. I created a child theme ‘myquark’ manually. And got the dreaded error.

    RuntimeException (400)
    Template “@images/grav-logo.svg” is not defined in “partials/base.html.twig” at line 44.

  2. The debugger showed that Quark theme was not executed.
  3. Ahh, I forgot to add myquark.php. After adding missing class definition error disappeared.

Made some other errors intentionally to see what happens. The following mistakes lead to the error:

  • If the myquark.yaml is defined incorrectly, e.g. incorrect prefixes name, the Quark theme is not executed.
  • If file myquark.php is not present, the Quark theme is not executed.
  • If name of class in myquark.php is defined incorrectly, the Quark theme is not executed.

In above cases, the Quark theme is not loaded at all. Therefor onTwigLoader() is not called to define the variable ‘images’.

Hope this helps you resolving the issue.

2 Likes