Custom Module Hubl Code If Elif - Going in Circles
SOLVE
Hi there-
Have a working custom module I created that is currently used on our site that allows folks to create a block that includes an Image, Heading Text and Rich Text Area with the class image-and-text
Currently there's an IF statement for the whole thing - shows Version 1 if there's a URL in the URL field and Version 2 with no <a wrapper if there is NO URL in the URL field.
NEW OPTION NEEDED We'd like to be able to add a class so we can specify a background color used for that block when in mobile view.
I've created a new field called Mobile BG Color - if it's set to None, I'd like the regular code to load.
<div class="image-and-text">
If it's set to Light Background, I'd like the code to load with the additional class of mobilelightbg
<div class="image-and-text mobilelightbg">
If set to Dark Background
<div class="image-and-text mobiledarkbg">
I am getting lost in code and not sure I'm even stacking the if in an if correctly.
Not hopeful since this attempt is a bit of a cluster now but if anyone chimes in, absolutely grateful!
Custom Module Hubl Code If Elif - Going in Circles
SOLVE
Hey thanks so much, AM closer. Tried the 2nd version first, didn't insert extra class.
Then tried the first option but the inserted CSS class stays at mobiledarkbg, it's not switching to mobilelightbg when you choose the Light BG option. Tried to tweak this code as is, couldn't get to switch, I know I'd need to edit the code to have it add no additional class if they pick None but figured just try to get this part working.
Custom Module Hubl Code If Elif - Going in Circles
SOLVE
Hey almost there, thanks! In this section: the {{ module.mobilebgcolor }} does display on the Preview screen but the {{module-mobilebgcolor.value}} did not.
<div>MOBILE COLOR {{ module.mobilebgcolor }}</div>
{{module.mobilebgcolor.value}}
So tweaked to remove .value and now the class IS showing and it's switching between dark and light
Custom Module Hubl Code If Elif - Going in Circles
SOLVE
Thanks so much - that was the last part of my 'overthinking' to clean up. Dropped in with the "none" option and working like a champ. Thanks!
ONE LAST QUESTIONS IF YOU'RE STILL AVAILABLE: I created a color picker for my Heading Text field, works just fine. Do you know if it's possible to do the same on the rich text field? Had no luck there.
Custom Module Hubl Code If Elif - Going in Circles
SOLVE
Awesome!
Yea, you can wrap the richtext in a div and as long as there aren't any overrides from the user, in the wysiwyg on text color, it should inherit the parent div color.
Something like:
<div style="color: {{widget_data.somecolorpicker.color}}">
//insert your richetext module here
</div>