Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

theme_config.XXX.enabled or theme_config.XXX == true works in different way

Solved by Karmalakas View solution

Started by Pedro M 5 years ago · 3 replies · 511 views
5 years ago

Hi

I have in blueprints.yaml in my theme the following:

YAML
latestposts:
      type: toggle
      label: Enable Latest Post in Sidebar
      highlight: 1
      default: 1
      options:
        1: PLUGIN_ADMIN.ENABLED
        0: PLUGIN_ADMIN.DISABLED
      validate:
        type: bool

If I want to filter the content if it is activated or deactivated (with if sentence), with theme_config.latestposts.enabled it does not work, however with theme_config.latestposts == true it works correctly.

Why is this happening? Is there something I am doing wrong?

Thanks.

5 years ago Solution

Why would you assume .enabled should work?
config.latestposts is a boolean values as you have defined in blueprint

YAML
      default: 1
      options:
        1: PLUGIN_ADMIN.ENABLED
        0: PLUGIN_ADMIN.DISABLED
      validate:
        type: bool

And default value is true

The selection is not the names, but the keys - 0 and 1
If you had

YAML
      default: enabled
      options:
        enabled: PLUGIN_ADMIN.ENABLED
        disabled: PLUGIN_ADMIN.DISABLED

then it would be config.latestposts == 'enabled' or config.latestposts == 'disabled'

5 years ago

@pmoreno,

Extending on the answer of @Karmalakas...

Mark the difference in variables used:

  • Variable theme_config.latestposts.enabled does not exist.
    Twig happily ignores/silences this issue by the way...
  • Variable theme_config.latestposts does exist.
last edited 10/27/21 by pamtbaau
5 years ago

Hello

I thought that it could be done the same as when we want to execute some code depending on whether a plugin is activated or not (config.plugins.XXX.enabled).

Thanks for your help

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 129 22 hours ago
General · by pamtbaau, 1 day ago
1 90 1 day ago
General · by Andy Miller, 2 days ago
0 74 2 days ago
General · by Marcel, 12 months ago
6 385 5 days ago
General · by Duc , 6 days ago
3 70 6 days ago