Toolkit Replacement - substring?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mstella1
    Mivite



    • Apr 2012
    • 338

    #1

    Toolkit Replacement - substring?

    Hi,
    I am trying to display the first 3 characters of a string and was using Toolkit substring to do that. Is there a replacement for the code below?

    Code:
    <mvt:item name="toolkit" param="newsubstring|zoom_code|l.all_settings:category:code,1,3" />
    <a href="&mvt:global:sessionurl;&Screen=ZOOMPRICE&[B][COLOR=#e74c3c]mvt:global:zoom_code[/COLOR][/B]">Pricing</a>
    Thanks,
    Mike
  • Nick
    Super Moderator











    • Dec 2011
    • 575

    #2
    You can use the substring_var function to do that functionality:

    HTML Code:
    <mvt:assign name="g.zoom_code" value="substring_var( l.settings:category:code, 1, 3 )" />
    <a href="&mvt:global:sessionurl;&Screen=ZOOMPRICE&mvt:global:zoom_code;">Pricing</a>
    Last edited by Nick; 06-16-23, 08:47 AM.
    Nicholas Adkins
    Technical Training Specialist / Miva, Inc.
    [email protected]
    https://www.miva.com/mivalearn

    Comment

    • mstella1
      Mivite



      • Apr 2012
      • 338

      #3
      Thank you that works!

      I can use what you gave me and I have another question. Is there a way to strip a character?

      A few of my categories have "_" in the category code. I can write conditionals for those but thought I would ask if there is a way to just use one line of code to strip the "_" from them.
      Last edited by mstella1; 06-16-23, 11:25 AM.

      Comment

      • Nick
        Super Moderator











        • Dec 2011
        • 575

        #4
        You can use the glosub function to strip a character from a variable, something like this:

        HTML Code:
        <mvt:assign name="g.strippedCategoryCode" value="glosub( l.settings:category:code, '_', '')" />
        &mvt:global:strippedCategoryCode;
        Nicholas Adkins
        Technical Training Specialist / Miva, Inc.
        [email protected]
        https://www.miva.com/mivalearn

        Comment

        • mstella1
          Mivite



          • Apr 2012
          • 338

          #5
          Perfect!

          Code:
          <mvt:assign name="g.price_code" value="substring_var( l.settings:subcat:code,1,4 )" />
          <mvt:assign name="g.strippedSubCategoryCode" value="glosub( g.price_code, '_', '')" />
          &mvt:global:strippedSubCategoryCode;

          Comment

          Working...
          X