I have a select list which has the following values where the key values are the same name as the css class name.
List1:
- prim-blue|Blue
- prim-black|Black
- prim-orange|Orange
We also have a text field which is surrounded by the following div tag below. Before the page renders, we want to take the value from list1 and assign it as a class to the div tag. We need assistance in figuring out how to get this to work using a preprocess hook.
/*css*/
prim-blue {
//some attribute
}
prim-black {
//some attribute
}
prim-orange {
//some attribute
}
/*field div tag */
<div id="target-element"> <h1> Some text values </h1> </div>
Desired results (when page renders):
**Assume list1 is set to Blue (key: prim-blue)
<div id="target-element" class="prim-blue"> <h1> Some text values </h1> </div>
Note (to provide more context):
I am using the paragraph module which a bundle that has a background color for list1 and the text field. Then on the basic page content type, i added a paragraph field.
Paragraph bundle fields:
- text (field_text)
- background color (field_bkg_clr) <-- the drop down list1
Basic Page content type:
- Header (field_pr_hdr, which is of type paragraph)