Forum

Thread tagged as: Question

Overriding perch_content_custom with a different content region

I have a list of events, the next of which is displayed on the website's homepage. Once in a while an event won't be on; for example the most recent event was snowed off. I commented out the perch_content_custom code and just added some hand written markup in its place, but that was a bit hacky.

I'm guessing the best way to approach an override would be to have a content region on the homepage with a text field, textarea, etc. plus a checkbox toggle. If that checkbox is checked (say with a value of override) it would show the contents of the override template rather than the next event.

How would I write an if statement to test if the override value is set in the override.html template and return the next event if it's not?

Thanks for taking a look :)

Martin.

Martin Underhill

Martin Underhill 5 points

  • 3 years ago

I've cracked it! I'm doing something like this:

$foo = perch_content_custom('Override', [
    'skip-template' => 'true',
    'return-html'   => 'true',
]);

$override = $foo['0']['override'];

if ($override == 'override') {
    perch_content_custom('Override', [
        'template' => 'override.html',
    ]);
} else {
 // list the next event
};