raindropdevs / RaindropSonataThemeBundle

Raindrop themes bundle for SonataAdminBundle
14 stars 12 forks source link

Variable "raindrop_sonata_theme" does not exist #7

Closed edertxodev closed 6 years ago

edertxodev commented 7 years ago

Hi,

Recently I've installed this Bundle in my Symfony 2.8 application, and after configure, it shows this error:

Variable "raindrop_sonata_theme" does not exist.

in vendor/raindrop/sonata-theme-bundle/Raindrop/SonataThemeBundle/Resources/views/standard_layout.html.twig at line 38  -
{% for stylesheet in sonata_admin.adminPool.getOption('stylesheets', []) %}
  <link rel="stylesheet" href="{{ asset(stylesheet) }}">
{% endfor %}
  <link rel="stylesheet" href="{{ asset('bundles/raindropsonatatheme/css/themes/' ~ raindrop_sonata_theme ~ '/bootstrap.min.css') }}" type="text/css" media="all" />
{% endblock %}
{% block javascripts %}

I follow the steps to configure it properly.

composer.json:

"sonata-project/admin-bundle": "^3.19",
"raindrop/sonata-theme-bundle": "dev-master"

Hope somebody can help me

matteocaberlotto commented 7 years ago

did you activate the bundle?

edertxodev commented 7 years ago

Yes, sure, in AppKernel.php. That's what you say?

matteocaberlotto commented 7 years ago

yes. it looks like the twig extension is not exposing that variable. i don't know exactly what's wrong, maybe the deprecation of the twig extension. to solve it, you could mimic the functioning of the twig extension by exposing the variable inside the template, that variable contains the theme label.

see Twig\Extension.php:

public function getGlobals() { return array( 'raindrop_sonata_theme' => $this->theme ); }

edertxodev commented 7 years ago

Yes, I did it on my own Twig extension class and it works.

Thanks a lot! :)

matteocaberlotto commented 7 years ago

no problem. i re-set the issue as open since it still requires a solution

lukepass commented 7 years ago

Hello, any news on this issue? I am receiving the same error and I can't use the bundle. Is there a temporary workaround?

Thanks.

matteocaberlotto commented 7 years ago

haven't fixed yet. the workaround is 3 comments above: just expose the 'raindrop_sonata_theme' variable as a twig global

lukepass commented 7 years ago

Could you please explain to me what should I do? Do I need to create a Twig Extension or I just need to set the variable as global? Where should I put the file?

Thanks.

matteocaberlotto commented 7 years ago

you can just set the variable as global

lukepass commented 7 years ago

What should I put as value?

# app/config/config.yml
twig:
    globals:
        raindrop_sonata_theme: '???'
matteocaberlotto commented 7 years ago

the name of the theme

lukepass commented 7 years ago

Thank you! Now it's working fine:

# app/config/config.yml

parameters:
    locale: en
    raindrop_sonata_theme: flatly

twig:
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'
    globals:
        raindrop_sonata_theme: '%raindrop_sonata_theme%'

raindrop_sonata_theme:
    theme: '%raindrop_sonata_theme%'

The only thing it's that the theme is not changing the sidebar color, do you know why?

Thanks.

amadohin commented 6 years ago

This fix also works on Symfony 3.3

You should add to the doc

Thank's!!