giansi / gravstrap-theme

Gravstrap Theme helps you to start a new Grav CMS site with Bootstrap support and several ready to use modules. It is also perfect to start a new Bootstrap custom theme, to create your unique design.
MIT License
7 stars 12 forks source link

Help with Child Theme #1

Closed onespaceman closed 8 years ago

onespaceman commented 8 years ago

I need help setting up a child theme that inherits gravstrap. I'm following this guide

When add mytheme.php it throws the error

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

files:

mytheme/ --- css/ --- --- custom.css --- blueprints.yaml --- mytheme.yaml --- mytheme.php

custom.css:

* {
  background: #FF0000;
}

mytheme.yaml

enabled: true
streams:
 schemes:
   theme:
     type: ReadOnlyStream
     prefixes:
       '':
         - user/themes/mytheme
         - user/themes/gravstrap-theme

mytheme.php

<?php
namespace Grav\Theme;

use Grav\Common\Theme;

class Mytheme extends Gravstrap
{
}
giansi commented 8 years ago

Hi, the mytheme.php is wrong. You extend Gravstrap but you do not use it and that's the reason of the exception. Anyway, you should extend GravstrapTheme instead of Gravstrap, which is a plugin:

use Grav\Theme\GravstrapTheme;

class Mytheme extends GravstrapTheme { }

And this should work.

At last, you can omit to create the mytheme.php and theme inheritance should also work.

Let me know if that fixes.

onespaceman commented 8 years ago

Thanks for the reply.

Ok, the php didn't work so I got rid of it. I did some more testing and overriding worked for twig templates, but not for css. I had to add this:

{% do assets.addCss('theme://css/custom.css',105) %}

to gravstrap-theme/templates/partials/base.html.twig on line 19 for it to work.

giansi commented 8 years ago

You have to copy the gravstrap-theme/templates/partials/base.html.twig to mytheme/templates/partials/base.html.twig then add your custom css {% do assets.addCss('theme://css/custom.css',105) %} to mytheme/templates/partials/base.html.twig template.

Let me know if that worked.

onespaceman commented 8 years ago

Yep. That's what I ended up doing.

giansi commented 8 years ago

Perfect! In the theme inheritance post, they suggest to copy the entire theme to your new one, then customize this last one. I prefer to copy only what I need to customize, but that's a matter of taste: both of them work as expected.

giansi commented 8 years ago

@onespaceman let me know if you build and launch a website based on this theme. Thank you

ossplus commented 8 years ago

Mytheme.php

namespace Grav\Theme;

use Grav\Theme\GravstrapTheme;

class Mytheme extends GravstrapTheme
{
}

then it show error:

Whoops \ Exception \ ErrorException (E_ERROR)

Class 'Grav\Theme\GravstrapTheme' not found 

when i use

namespace Grav\Theme;

use Grav\Common\Theme;

class Mytheme extends Theme
{
}

it works.

datavoyager commented 8 years ago

It's possible that this is an autoloading problem.

I get the same error when trying to extend the Gravstrap theme using the advice given at http://learn.getgrav.org/themes/customization#theme-inheritance

When I add the following to composer.json

"autoload": {
        "psr-4": {
            "Grav\\": "system/src/Grav"
        },
        "files": ["system/defines.php", "user/themes/gravstrap-theme/gravstrap-theme.php"]
    },

it works as expected.

giansi commented 8 years ago

Another solution is to require the GravstrapTheme as follows:

require_once(DIR . '/../gravstrap-theme/gravstrap-theme.php');

jbonlinea commented 6 years ago

Hi guys,

It's an old thread, but it helped me and I have a complementary info.

As today up to date version of grav and gravstrap, you

In the end mytheme.php looks like this and it's working.

<?php
namespace Grav\Theme;

class Mytheme extends GravstrapTheme
{
   // Some new methods, properties etc.
}
?>

Hope this might help

Cheers