twig - Grav CMS: how to show/hide parts of the page depending on conditions? -


the grav's documentation describes how whole page or folder hidden unregistered users. describes how whole page seen particular user groups.

but pieces of page, let's say, links or private info want show on conditions?

ok, registered users found snippet @ login plugin docs:

{% if grav.user.authenticated %}     content registered users goes here {% endif %} 

but going wider - how can show/hide pieces of particular page depending on custom logic in php code, i.e. not user related?

i'm thinking twig/shortcode plugin, like:

{% if some.custom.condition.or.php.function %}    hidden content goes here {% endif %} 

or

[hidden_if_something] hidden content goes here [/hidden_if_something] 

but not sure how should implemented. working examples appreciated. thanks.

there recipe in grav documentation here. provides example of how render output of php code result in twig template.

in example create plugin, , implement twig extension providing access php function. can call php function in twig template.

{{ example() }} 

following example, can implement whatever logic in php, , call function in twig if statement.

{% if example() == true %}    conditional output {% endif % 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -