Is there a way to set a template’s visibility with it’s own conditions to be turned on and off within an ACF options page?
This is easy to do. You can use for example either of these two filters bricks/screen_conditions/scores
& bricks/active_templates
to manipulate your active templates.
I used the later to create this filter, which disables the header-template on the front-page if a acf-options-field is enabled.
// Disable Header Template on the Home page if ACF Options Field is 'true'
// functions.php
add_filter('bricks/active_templates', function ($active_templates, $post_id, $content_type) {
// Only run logic on the frontend
if (! bricks_is_frontend()) return $active_templates;
// use these to var_dump the variables:
// Bricks\Helpers::pre_dump($active_templates);
// Bricks\Helpers::pre_dump($post_id);
// Bricks\Helpers::pre_dump($content_type);
// Return if $content_type is not 'content'
if ($content_type !== 'content') return $active_templates;
// Return if it's not the Front page
if (!is_front_page()) return $active_templates;
// Get your Options field
$disableHeader = get_field('disable_header_on_condition', 'option');
if ($disableHeader) {
$active_templates['header'] = false;
}
return $active_templates;
}, 10, 3);
resources:
Thank you. Sadly I have no idea how PHP works, I was hoping for something no code. I think I will start studying now haha
I’m afraid it is not possible without writing some php.