Substitutions - Can two strings be compared?

5 years 11 months ago - 5 years 11 months ago #304677 by bascherz
There are occasions when one content item needs to be compared with another in an article. I have CB Content Bot installed and enabled. The [cb:if ...] substitution construct is only described in the context of comparing profile fields with a string. I am trying to use it to compare two strings that are produced by other (non-CB) content bots. The example below shows the exact code. Please note that all placeholders in this example are produced by other content bots, not by CB.
[cb:if "{street_address}" != "{cb_address}"]<span style="background-color:powderblue;">{street_address}</span>[cb:else]{street_address}[/cb:else][/cb:if]

This yields a "true" result even when {street_address} and {cb_address} are identical.

There is actually a CB field defined as cb_address. Could this be interfering, or is cb:if not able to compare two strings?

Thanks in advance.

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

5 years 11 months ago #304678 by bascherz
Replied by bascherz on topic Substitutions - Can two strings be compared?
Just as a follow-up, I was able to accomplish the desired effect quite easily using Regular Labs Sourcerer plugin and PHP code.

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

5 years 10 months ago #304694 by krileon
Replied by krileon on topic Substitutions - Can two strings be compared?
Your IF substitution should be as follows.

[cb:if cb_address!="{street_address}"]<span style="background-color:powderblue;">{street_address}</span>[cb:else]{street_address}[/cb:else][/cb:if]

There is no substitution usage to compare a custom string to a custom string. It's not a generalized string to PHP IF statement usage. It's specifically for comparing against field values with a few custom additions (e.g. language, usergroup, and view access level compares). The above will however only work if the replacement for {street_address} is done before CB Content Bot parses for substitutions so load order of your content plugins will be important.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: nant

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.205 seconds

Facebook Twitter LinkedIn