Skip to Content Skip to Menu

🌟 CB Editor Assistant 1.0.0 is here! Discover our new AI Joomla Plugin that wrote its story! (and this banner!)
Start at just $12.50/month* or 💸 save 30% with our 🛍️ Black Friday Intro Offer for your subscription's lifetime
🎉 Black Friday sale is here! Great savings on professional and developer memberships! Get 25% off now with code BLACK-FRIDAY-2024!

Substitutions - Can two strings be compared?

  • bascherz
  • bascherz
  • OFFLINE
  • Posts: 228
  • Thanks: 29
  • Karma: 11
6 years 6 months ago - 6 years 6 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.
Code:
[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
Last edit: 6 years 6 months ago by bascherz.

Please Log in or Create an account to join the conversation.

  • bascherz
  • bascherz
  • OFFLINE
  • Posts: 228
  • Thanks: 29
  • Karma: 11
6 years 6 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 or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48560
  • Thanks: 8292
  • Karma: 1445
6 years 6 months ago #304694 by krileon
Replied by krileon on topic Substitutions - Can two strings be compared?
Your IF substitution should be as follows.

Code:
[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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum