nliautaud / pico-pages-list

A pages lists plugin for Pico CMS, with nested pages, pages filtering and HTML navigation.
MIT License
12 stars 8 forks source link

Know if the plugin is enabled trough Twig #12

Closed lollita closed 6 years ago

lollita commented 6 years ago

Is it possible to use such a condition in twig? ex.

{% if config.PicoFilePrefixes.enabled %}
...
{% else %}
...
{% endif %}
nliautaud commented 6 years ago

Hi, what are you trying to achieve here about pico-pages-list ? You can use conditions in twig, but the setting you target isn't valid.

lollita commented 6 years ago

I know it but is the which target valid?

nliautaud commented 6 years ago

I'm not the author of PicoFilePrefixes, but it seems that you trying to target AbstractPicoPlugin::$enabled. It's not a config setting, and I don't think Pico let you access that from Twig. You should look/ask at Pico issues directly if there is a way to know from Twig if a plugin is enabled.

lollita commented 6 years ago

ok i wrong to write not : {% if config.PicoFilePrefixes.enabled %} but : {% if config.PicoPagesList.enabled %}

nliautaud commented 6 years ago

Note that if there is no "official" way to do it, you could set the following setting :

$config['PicoPagesList.enabled'] = true;

And target that on your theme using an array syntax :

{% if config['PicoPagesList.enabled'] %}
lollita commented 6 years ago

i tryed it but not work. Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "exclude" filter.' do it work for you?

nliautaud commented 6 years ago

This error is related to a theme calling PicoPagesList-specific features (exclude filter here) while PicoPagesList is missing or disabled.

Are you trying to make a theme with an optional PicoPagesList support ? Working example :

{% if config['PicoPagesList.enabled'] %}
        {% include 'picopageslist-navigation.twig' %}
{% endif %}
lollita commented 6 years ago

if i set $config[ 'PicoPagesList.enabled' ] = false and use {% if config['PicoPagesList.enabled'] %} the condition return true and theme not work

but

if i set //$config[ 'PicoPagesList.enabled' ] = false and use {% if config['PicoPagesList.enabled'] %} the condition return false and theme work

nliautaud commented 6 years ago

You seems to have a typo again, this is PicoPagesList instead of PicoPlacing. Please copy directly the related parts in your theme and config.php.

lollita commented 6 years ago

excuse me, i have wrong to copy and past but the way remains unchanged. I corrected the post.

nliautaud commented 6 years ago

I cannot reproduce that behavior, sorry. If this setting and the twig part are set correctly and not overrided, there is no reason I can think of for $config['PicoPagesList.enabled'] = false; to return true in your theme.

Feel free to share your Pico version and copy your template and config files.