Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

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 · 662 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 Andy Miller, 1 week ago
0 144 1 week ago
General · by lynbor, 1 month ago
3 460 2 weeks ago
General · by lynbor, 3 weeks ago
7 597 2 weeks ago
General · by Harry, 2 weeks ago
0 180 2 weeks ago
General · by Old Man Umby, 1 month ago
2 323 4 weeks ago