2

I have a color field in content type -> page fields. And i want to read the values of this field and pass this value as a background color(bootstrap subtheme) to element for main content ( - from page,tlp.php). And only for node type -> page.

In my template.php i tried to use function theme_preprocess_page. My code:

function theme_preprocess_page(&$vars) {

    if (isset($vars['node'])) {

        $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type . 'page';

        // check the node type and specific field in not empty  
        if (($vars['node']->type = 'page') && (!empty($content['field_color']['#items'][0]['value']))) {

            //read the value of color field
            $bg_color = $content['field_color']['#items'][0]['rgb'];            

        }
    }
}

but i dont know how to pass the value of color field ($content['field_color']) to section style attributes. Should i use $vars['attributes_array']['style'] ? and how to pass it to section element style.

Help please.

2
 $color = preg_replace("/#/i", "", $bg_color);  
$vars['classes_array'][] = $color;
 $vars['style'] = "style='background-color:$bg_color'";
  • Thx but how to render this for a section. – user1597594 May 6 '16 at 12:03
  • can you please elaborate what u mean by section ?? – Shreya Shetty May 6 '16 at 12:05
  • page.tpl.php element <section> in main content container -> section element in bootstrap theme. <div class="row"> <section<?php print $content_column_class?> style="i want to render value of colo field here"> </section> </div> – user1597594 May 6 '16 at 12:44
  • <div <?php if(!empty($style)) print $style; ?> class="<?php print $classes; ?>"></div> the color will be rendered there – Shreya Shetty May 6 '16 at 12:51
  • it renders only <div class="page"></div> – user1597594 May 6 '16 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.