Closed onespaceman closed 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.
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.
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.
Yep. That's what I ended up doing.
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.
@onespaceman let me know if you build and launch a website based on this theme. Thank you
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.
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.
Another solution is to require the GravstrapTheme as follows:
require_once(DIR . '/../gravstrap-theme/gravstrap-theme.php');
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
GravstrapTheme
and not Gravstrap
, I assume this is related to line 6 of gravstrap-theme.php
where the class is declared class GravstrapTheme extends Theme
use Grav\Common\GravstrapTheme;
oruse Grav\Common\Theme;
in your Mytheme.php
as it is already declared in gravestrap-theme.php
line 4In 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
I need help setting up a child theme that inherits gravstrap. I'm following this guide
When add mytheme.php it throws the error
files:
mytheme/ --- css/ --- --- custom.css --- blueprints.yaml --- mytheme.yaml --- mytheme.php
custom.css:
mytheme.yaml
mytheme.php