Adding a select option to a div class

Permalink Browser Info Environment
Hi

I've set up a block and wanted to have the ability to change the styles of the block dependant on the selection we choose - so I've set up a block with a few select options of red, green and blue

If I then choose the blue option the class is applied to the div wrapper and the styles can kick in and change the box to red or blue ect.

I've tried this but I don't know the php code to place the option into the div. Tried this but not loaded in.

<div class="serviceBox" id="<?php echo $field_5_select_value-> value ?>">

Is this possible or can you guide me in the right direction?
Cheers, Matt

Type: Discussion
Status: New
Matteld80
View Replies: View Best Answer
jordanlev replied on at Permalink Best Answer Reply
jordanlev
I'd suggest you create classes in your block's css for different colors. For example, ".red", ".green", ".yellow".
Then in the block view.php file, you can output the class that corresponds to the selection of the dropdown. For example (in your view.php file):
<?php
if ($field_5_select_value == 1) {
  $color_class = 'red';
} else if ($field_5_select_value == 2) {
  $color_class = 'green';
} else if ($field_5_select_value == 3) {
  $color_class = 'yellow';
} else {
  $color_class = 'black'; //default if nothing is selected
}
?>
<div class="serviceBox <?php echo $color_class; ?>">


When the block was first created, it should have put the "if" statements into the view.php code (if you've since deleted it, you could temporarily create another block with the same options, copy the code from that new block's view.php file, paste it into your existing one, then uninstall/delete the other block).

Hope that helps!

-Jordan
Matteld80 replied on at Permalink Reply
Matteld80
Cool thanks for this Jordan

WE did figure a workaround by adding

<div class="serviceBoxFULL Serv<?php echo $field_5_select_value;?>">

and then setting a Serv2,Serv3,Serv4 classes in the stylesheet

Demo here -
http://bigcopystudio.co.uk.gridhosted.co.uk/...

Will put your way on a custom template withing the same set :)

Matt

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.