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!
ORIGINAL CODE
{% if widget.optional_url %}
<div class="image-and-text">
<a href="{% inline_text field="optional_url" value="{{ module.optional_url }}", no_wrapper=True %}">
<img alt="{% inline_text field="image_alt_text" value="{{ module.image_alt_text }}", no_wrapper=True %}" src="{{ module.image_src_url }}"
width="{{ module.width }}" height="auto" style="display: block; margin: 0px auto;"/>
</a>
<div> </div>
<a href="{% inline_text field="optional_url" value="{{ module.optional_url }}", no_wrapper=True %}">
<{{ module.heading_type }} style="color: {{ module.header_text_color }}; text-align: center; font-weight: {{ module.header_font_weight }};">{% inline_text field="heading_text_under_image" value="{{ module.heading_text_under_image }}" %}</{{ module.heading_type }}>
</a>
{% if widget.text %}
{% inline_rich_text field="text" value="{{ module.text }}" %}
{% endif %}
</div>
{% else %}
<div class="image-and-text">
<img alt="{% inline_text field="image_alt_text" value="{{ module.image_alt_text }}", no_wrapper=True %}" src="{{ module.image_src_url }}"
width="{{ module.width }}" height="auto" style="display: block; margin: 0px auto;"/>
<div> </div>
<{{ module.heading_type }} style="color: {{ module.header_text_color }}; text-align: center; font-weight: {{ module.header_font_weight }};">{% inline_text field="heading_text_under_image" value="{{ module.heading_text_under_image }}" %}</{{ module.heading_type }}>
{% if widget.text %}
{% inline_rich_text field="text" value="{{ module.text }}" %}
{% endif %}
</div>
{% endif %}
NEW CODE ATTEMPT
{% if widget.optional_url %}
{% if module.mobilebgcolor.value == 'mobilelightbg' %}
<div class="image-and-text mobilelightbg">
<a href="{% inline_text field="optional_url" value="{{ module.optional_url }}", no_wrapper=True %}">
<img alt="{% inline_text field="image_alt_text" value="{{ module.image_alt_text }}", no_wrapper=True %}" src="{{ module.image_src_url }}"
width="{{ module.width }}" height="auto" style="display: block; margin: 0px auto;"/>
</a>
<div> </div>
<a href="{% inline_text field="optional_url" value="{{ module.optional_url }}", no_wrapper=True %}">
<{{ module.heading_type }} style="color: {{ module.header_text_color }}; text-align: center; font-weight: {{ module.header_font_weight }};">{% inline_text field="heading_text_under_image" value="{{ module.heading_text_under_image }}" %}</{{ module.heading_type }}>
</a>
{% if widget.text %}
{% inline_rich_text field="text" value="{{ module.text }}" %}
{% elif module.mobilebgcolor.value == 'mobiledarkbg' %}
{% else %}
<div class="image-and-text mobiledarkbg">
<a href="{% inline_text field="optional_url" value="{{ module.optional_url }}", no_wrapper=True %}">
<img alt="{% inline_text field="image_alt_text" value="{{ module.image_alt_text }}", no_wrapper=True %}" src="{{ module.image_src_url }}"
width="{{ module.width }}" height="auto" style="display: block; margin: 0px auto;"/>
</a>
<div> </div>
<a href="{% inline_text field="optional_url" value="{{ module.optional_url }}", no_wrapper=True %}">
<{{ module.heading_type }} style="color: {{ module.header_text_color }}; text-align: center; font-weight: {{ module.header_font_weight }};">{% inline_text field="heading_text_under_image" value="{{ module.heading_text_under_image }}" %}</{{ module.heading_type }}>
</a>
{% if widget.text %}
{% inline_rich_text field="text" value="{{ module.text }}" %}
{% endif %}
{% endif %}
{% endif %}
</div>
{% else %}
<div class="image-and-text">
<img alt="{% inline_text field="image_alt_text" value="{{ module.image_alt_text }}", no_wrapper=True %}" src="{{ module.image_src_url }}"
width="{{ module.width }}" height="auto" style="display: block; margin: 0px auto;"/>
<div> </div>
<{{ module.heading_type }} style="color: {{ module.header_text_color }}; text-align: center; font-weight: {{ module.header_font_weight }};">{% inline_text field="heading_text_under_image" value="{{ module.heading_text_under_image }}" %}</{{ module.heading_type }}>
{% if widget.text %}
{% inline_rich_text field="text" value="{{ module.text }}" %}
{% endif %}
</div>
{% endif %}