WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 20.10.2021 01:46:57

losttrip
Mitglied

OFA OneForAll style text depending on switch state

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:

1a488426e1e5fa757aafbabcc4153df1.png

The Switch is field_id 2:

ce8bb7471c2287de542c92fd1571bff9.png

This is the "mod_hrhshop_item_fields" table showing the value for field_id 2:

86c924b987f2fd0985b180d53c1b4b4b.png

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

#2 20.10.2021 07:06:52

florian
Administrator

Re: OFA OneForAll style text depending on switch state

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!

Offline

Liked by:

losttrip

#3 20.10.2021 10:44:24

losttrip
Mitglied

Re: OFA OneForAll style text depending on switch state

Thank you so much.  This works perfectly, and it opens my mind to other possibilities using droplets!

Offline

Liked by:

florian

Fußzeile des Forums

up