We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47308
    • 68 Posts
    Hi. I have a text template variable where I want to strip out any spaces so I can use the value in an HTML tag. Can anyone point me in the right direction? Alternatively, I could replace the spaces with underscores or dashes.

    Thanks.

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      Try one of these where you want the TV value:

      (remove spaces)
      [[*tvName:replace=` ==`]]


      (convert to dash)
      [[*tvName:replace=` ==-`]]


      (convert to underscore)
      [[*tvName:replace=` ==_`]]


      A faster alternative would be a custom snippet:

      [[!ChangeSpaces? &val=`[[*tvName]]` ]]


      <?php
      /* ChangeSpaces snippet */
      $replacement = ''; // or put a - or _ inside the quotes
      
      $val = $modx->getOption('val', $scriptProperties);
      return str_replace(' ', $replacement, $val); 



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 47308
        • 68 Posts
        Quote from: BobRay at Aug 25, 2014, 11:01 PM
        Try one of these where you want the TV value:

        A faster alternative would be a custom snippet:

        [[!ChangeSpaces? &val=`[[*tvName]]` ]]


        <!--?php
        /* ChangeSpaces snippet */
        $replacement = ''; // or put a - or _ inside the quotes
        
        $val = $modx--->getOption('val', $scriptProperties);
        return str_replace(' ', $replacement, $val); 




        The custom snippet worked perfectly. Thank you.
          • 3749
          • 24,544 Posts
          Glad I could help. Thanks for reporting back. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting