WBCE CMS – Way Better Content Editing.
You are not logged in.
WBCE Version: 1.5.0
PHP Version: 7.4.23
OFA 1.1.6 (renamed - hrhshop)
Is there a way to style (text colour) the displayed text based on the state of a switch field?
When the switch is set to "off" (default), the resulting text "In Stock" is displayed in the default font colour (black). When the switch is turned to "on", I would like the text "Currently Out of Stock" displayed in Red.
Here is the field settings:
The Switch is field_id 2:
This is the "mod_hrhshop_item_fields" table showing the value for field_id 2:
a:2:{i:0;s:0:"";i:1;s:1:"1";}
This is the page setting (Overview (Item-Loop)) for the switch display:
<div class="shop_item_stock">[IN_STOCK]</div>
Offline
This can be done with a droplet.
Create a droplet named "stock" and the following code:
if (!isset($s)) {$s='';}
if (stripos($s,"out of") != false) {
return '<span style="color:red">'.$s.'</span>';
} else {
return $s;
}
In the OfA field template for the switch, replace
[CUSTOM_CONTENT]
with
[[stock?s=[CUSTOM_CONTENT]]]
Code allein macht nicht glücklich. Jetzt spenden!
Und Danke an alle, die diesem Aufruf schon gefolgt sind!
Offline
losttrip
Thank you so much. This works perfectly, and it opens my mind to other possibilities using droplets!
Offline
florian