Included grav-logo.svg missing on extending theme


#1

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


#2

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.


#3

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


#4

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.


#5

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


#6

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.


#7

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.


#8

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


#9

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.