Sauter la navigation

[Résolu] If conditions in field and text block not evaluating correctly

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
The user has built some conditional blocks on taxonomy terms, but they were not working.

Solution:
The conditions were not correctly set. Check a detailed explanation here https://toolset.com/forums/topic/if-conditions-in-field-and-text-block-not-evaluating-correctly/#post-1798507

This support ticket is created Il y a 4 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Marqué : 

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Daniel Stadeli Il y a 4 années et 3 mois.

Assisté par: Jamal.

Auteur
Publications
#1797233
Process taxonomy custom field color.png
process select field values.png
process field.png
Prozessgestaltung Grafik.jpg

Hi,

I'm working my way to output a class based on the value of a custom select field (prozess-schritt). The IF wizard inside the fields and text block gave me solution 1), which never evaluates to true. I finally came up with the code in 2) and it seems to work.

My question is, why does 1) not work but 2) works?

<p>1:[wpv-conditional if="( $(wpcf-prozess-schritt) eq 'Analyse' )" ] Analyse [/wpv-conditional] </p>
<p>2:[wpv-conditional if="( '[types field='prozess-schritt'][/types]' eq 'Analyse' )" ] Analyse [/wpv-conditional] </p>

URL: lien caché

Background:
My goal is to make the each box (process field.png) in the color of the color wheel (Prozessgestaltung Grafik.jpg), depending on which process the post belongs to.

My initial idea was to use a custom taxonomy (process taxonomy...png) and add a custom field with the color code plus another one for sorting on the front end. It turns out I cannot access these custom taxonomy values in Toolset Blocks. So I reverted back to doing a regular custom field (select) as part of Fallverlaeufe post type (process select field values.png).

Maybe you have a more elegant solution? I will need to use this color throughout the website and I would have to use 7 if statements each time.

I know Nigel loves a challenge like this, so I'm hoping he may work on this ticket?

#1798051
View Loop.png
Colors html output.png

Nigel,
I have kept working on this project, but under a new URL so the original problem stays intact, but you can see some progress.
Currently I got this: lien caché

My conditional code is inserted in a field and text block:
[wpv-conditional if="( '[types field='prozess-schritt'][/types]' eq 'Situationserfassung' )" ]<div style="background-color: #005BA2; text-align: center; color: white; font-size: medium; font-weight: bold;", class="situation">Situationserfassung</div>[/wpv-conditional]
[wpv-conditional if="( '[types field='prozess-schritt'][/types]' eq 'Analyse' )" ]<div style="background-color: #007BBF; text-align: center; color: white; font-size: medium; font-weight: bold;", class="analyse">Analyse</div>[/wpv-conditional]
[wpv-conditional if="( '[types field='prozess-schritt'][/types]' eq 'Diagnose' )" ]<div style="background-color: #0098DB; text-align: center; color: white; font-size: medium; font-weight: bold;", class="diagnose">Diagnose</div>[/wpv-conditional]
etc.

In this solution I'm outputting different html code to format the title bar dynamically with the correct color.

How can make it so it will affect the whole view loop (the complete block / shaded square you see on the front end)?
Div or span will only affect one line, not the whole block.

#1798507

Hello and thank you for contacting the Toolset support.

Nigel does not work on Saturdays, If you would like me to pass him this ticket on Monday, let me know.

Let's first answer your question why does 1) not work but 2) works?
From the definition on your custom field, as seen in the screenshot "process select field values.png". The values for the fields are (1 to 7) but the labels are actually strings(words). So:

[wpv-conditional if="( $(wpcf-prozess-schritt) eq 'Analyse' )" ] Analyse [/wpv-conditional]

This will return the value of the field(1 to 7) rather than its label.
But this:

[wpv-conditional if="( '[types field='prozess-schritt'][/types]' eq 'Analyse' )" ] Analyse [/wpv-conditional] 

Will return the label, instead of the value. If you add the argument output="raw", it will return the value(1 to 7)

If you want to use the first condition for the "Analyse" word, you will need to set it as:

[wpv-conditional if="( $(wpcf-prozess-schritt) eq '2' )" ] Analyse [/wpv-conditional]

Maybe you have a more elegant solution? I will need to use this color throughout the website and I would have to use 7 if statements each time.
We can achieve this in different ways. You may want to use color codes instead of the values(1 to 7). This way you can customize the value without needing a condition. For example, instead of 7 conditions like this:

[wpv-conditional if="( '[types field='prozess-schritt'][/types]' eq 'Situationserfassung' )" ]<div style="background-color: #005BA2; text-align: center; color: white; font-size: medium; font-weight: bold;", class="situation">Situationserfassung</div>[/wpv-conditional]

You can use only one line:

<div style="background-color: [types field='prozess-schritt' output='raw'][/types]; text-align: center; color: white; font-size: medium; font-weight: bold;", class="situation">[types field='prozess-schritt'][/types]</div>

Notice, that we used output='raw' to return the color code, and we did not use it to return the label.

With this solution you "can't" use $(wpcf-prozess-schritt) in conditions, as it will return the value(color code).

You may, also, want to keep the field as it is and add a field that will hold the color. Then using custom code, you will save the appropriate color in the color field, based on the value of this field.
Or using custom styles bound to CSS classes and make 7 styles for classes such as ('my-bg-1', 'my-bg-2', for the available values(1 to 7)). Then use it inside your markup:

<div class="situation my-bg-[types field='prozess-schritt' output='raw'][/types]">[types field='prozess-schritt'][/types]</div>

How can make it so it will affect the whole view loop (the complete block / shaded square you see on the front end)?
Div or span will only affect one line, not the whole block.

This is true for the span tag. But it is not true for the div tag. Check the following articles. Span tags are inline tags and meant to be used inside a line. Div, on the other hand, is used as a container for other tags, it can contain other divs, that contain p tags, that contain a and span tags.
- lien caché
- lien caché

I hope this helps. Let me know if you have any questions, or if you prefer that Nigel keeps working with you on this ticket.

#1806209

My issue is resolved now. Thank you!