First block - new guy question

Permalink
I need to make or find a block that will allow me to set say 3 pieces of pre-defined text as a site admin. Green, Amber, Red. Then I want to be able to allow a privileged user to set only one to be actively displayed at a time. I can create the input part and the db.xml.

What's the best way to go about telling the display to only show the one marked as active?


Ultimately what I need to build is a way for a site admin to set pre-defined messages for road conditions and reporting status for employees. Then we'd allow a few people access to be able to select which message is being displayed based on weather, etc. This way they aren't in there just entering text in a Rich Text box, freehand.

Is there a block that might already do this that I missed even?

 
jakobfuchs replied on at Permalink Reply
jakobfuchs
If I understand your problem correctly this could be implemented with a custom "select" page attribute. Then you can use the built-in 'Page Attribute Display' block type to output the value.
TonyLudwikowski replied on at Permalink Reply
Might work. Just need to figure out the select page attribute part.
hutman replied on at Permalink Reply
hutman
You should be able to create a select attribute Dashboard -> Pages & Themes -> Attributes enter your 3 colors in the options. Then on the front end check that attribute on the current page like this

$c = Page::getCurrentPage();
$attribute_value = $c->getAttribute('attribute_handle');
if($attribute_value === 'Value 1'){
//do things for value 1
} elseif($attribute_value === 'Value 2'){
//do things for value 2
} elseif($attribute_value === 'Value 3'){
//do things for value 3
}