In this use case, I believe inline styles are the way to go. There are methods to write a CSS file in your module or theme, for example, but since users can select, and update at any time, any color code, all situations would be very difficult or messy to manage. Inline styles are not ideal in the grand scope of things, but with multiple users, and multiple hex values reaching the millions, sometimes requirements make our choices for us. And plus, we just want to get it done.
Below assumes the view shows nodes, both fields are on the content type, and the title being styled is the node title
, not the views title
. This is best achieved setting the view to display content, and utilizing template files for your chosen display mode such as node--content-type--teaser.tpl.php
.
node--content-type--rotating-hero.tpl.php:
<section>
<h1
title="<?php print render($title); ?>"
alt="<?php print render($title); ?>"
<?php if (isset($content['field_background_colour'])) : ?>
style="color: #<?php print $content['field_background_colour']['#items'][0]['value']; ?>;"
<?php endif; ?>
>
<?php print render($title); ?>
</h1>
</section>
Here, each .views-row
will contain an individual node display, and you can focus your javascript and CSS on those for the slider.
*multiple h1 tags on the same page need to be wrapped in a <section>
tag, otherwise, use h2 tags.
*Templates are related to structure and usage. Views templates are for the structure and layout of content aggregation, node templates are the structure of individual entities. Wherever the field (or desired data) resides is the best place to theme template files.
Below assumes you need to style the views title
itself...
will need more info about where the color field lives. If user profile, for example, you will need to load the user object to access the field value.
MYMODULE.module:
function MYMODULE_views_pre_render(&$view) {
if ($view->name == 'view_name') {
$view->build_info['title'] = "custom title";
}
}
template.php:
function MYTHEME_views_pre_render(&$variables) {
if (&$variables['view']->name == 'view_name') {
&$variables['view']->build_info['title'] = "custom title";
}
}
[field_background_colour]
is not working in your view, it could just be a formatting issue for that field. Inspect the element and how it is actually being printed in the DOM.