Announcement

Collapse
No announcement yet.

Check if a string contains substring on a page template

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Check if a string contains substring on a page template

    Hi, Is there a way to check if a string contains a substring? I could use something like the code below to check if the string fully matches:

    <mvt:foreach iterator="item" array="order:items">
    <mvt:if expr="l.settings:item:name EQ 'Specialty Product 321'">

    </mvt:if>
    </mvt:foreach>

    I would like to instead just check if that variable contains "Specialty Product", any help would be appreciated.

    #2
    stickerc you could use the CIN to check if the string is in the variable:

    Code:
    <mvt:foreach iterator="item" array="order:items">
    <mvt:if expr="'Specialty Product 321' CIN l.settings:item:name">
    
    </mvt:if>
    </mvt:foreach>
    The CIN operator is case-insensitive. It will find a match if the letters are the same regardless of case (upper or lower). So 'at' CIN 'Cat' or 'at' CIN 'CAT" would both return 2.

    You could also use the IN operator:
    The IN operator is case-sensitive. It will find a match only if the sub-string has the same case (upper or lower) letter-by-letter. So 'at' IN 'Cat' would return 2, but 'at' IN 'CAT" would return 0 (zero).
    Nicholas Adkins
    Technical Training Specialist / Miva, Inc.
    [email protected]
    https://www.miva.com/mivalearn

    Comment


      #3
      You can also do this:

      <mvt:if expr="'specialty product 321' IN tolower(l.settings:item:name)"> Same as CIN. Technically faster but probably wouldn't notice the difference.
      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment

      Working...
      X