Transforming page attribute into css class

Permalink
Hi,

I tried to transform the page attribute (user input in page properties) into a css class for the right div-box. Can u tell me why this doesn't work?

As class in the div statement there appears simply nothing...

<?php
$backgrounds = array('violett'    => 'bgr_violet',
                      'orange'    => 'bgr_orange',
                      'blau'      => 'bgr_blue',
                      'gruen'   => 'bgr_green',
                      'rot'      => 'bgr_red',
                      'grau'      => 'bgr_gray');
$background = $backgrounds["$c->getAttribute('bgr_af_1')"];
?>
<div class="col-sm-3 af <?php echo $background; ?>">
...

 
enlil replied on at Permalink Reply
enlil
I believe you're missing
$c = Page::getCurrentPage();
at the beginning of your code
enlil replied on at Permalink Reply
enlil
<div class="col-sm-3 af <?php echo $background; ?>">


should look something like

<div class="col-sm-3-af-<?php echo $background; ?>">


and you should name all the color options like "bgr-violet"

so you classes would be like "col-sm-3-af-bgr-violet"
core77 replied on at Permalink Reply
col-sm-3 is a class from bootstrap3.

af is an own class which I need.

...and at last wanted to define the backgroundcolor through page attribute.

When i directly use c->getAttribute('bgr_af_1') in the div statement it works very well! Sure, in this case the css class must be named the same...
core77 replied on at Permalink Reply
My solution looks like this:


Page attribute is 'bgr_af_1'

In the template I do this:
<div class="col-sm-3 af <?php echo $c->getAttribute('bgr_af_1'); ?>">


And in the main.css I format the bgr_af_1 class.