This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello, i was wondering if there is any way to obtain a list of used snippets with their properties inside the layout's Twig or the onStart
PHP code section: at this time i'm doing the following in the onStart
section of the page layout, but i'm sure there should be a better way:
use RainLab\Translate\Classes\Translator;
function onStart() {
$translator = Translator::instance();
$locale = $translator->getLocale();
$data = strtolower($this->page->apiBag['staticPage']->getTranslateAttributes($locale)['markup']);
$this['has_gallery'] = strpos($data, 'data-property-showgallery="1"') !== FALSE;
$this['has_gmaps'] = strpos($data, 'data-property-showgmaps="1"') !== FALSE;
$this['has_docs'] = strpos($data, 'data-property-showdocuments="1"') !== FALSE;
$this['has_videos'] = strpos($data, 'data-property-showvideos="1"') !== FALSE;
}
And later on in my layout's Twig code for video data i do:
...
<div class="col-lg-{% has_videos ? 8 : 12 %}">...</div>
{% if has_videos %}<div class="col-lg-4">...</div>{% endif %}
...
It would be of great use: often you have to deal with creating a dynamic number of columns in the same layout, depending on the availability of some content; in my case if the videos
content is present the layout will be presented on two columns, else a single one. To be able to discern this at layout time would be great, and although the mentioned workaround
works, it's not clean and prone to errors, and also i can't check if the video data is really there or not.
Thanks for any feedback!
Last updated
1-1 of 1