Announcement

Collapse
No announcement yet.

truncate custom field

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

    truncate custom field

    I could use some help. I was trying to limit the characters on a customfield using Tool Kit but must be doing something wrong. Is there a 'new' method I could use to truncate the custom field shortdesc to 90 characters? I don't want to use the CSS method.

    <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'shortdesc', g.shortdescrip)" />
    &mvt:global:shortdescrip;
    </mvt:if>

    I appreciate any help.

    #2
    Hi, if you want to limit the number of characters in the string, one very easy way to do it is like this:

    <mvt:eval expr="substring(g.shortdescrip,1,90)" />

    The first number is where you want to start, in this case I'm guessing the first character. The next number is how many characters you want. If you are going for SEO description, then you want either 154 or the new google 320. Let's say you want 154 characters, but you don't want to just "cut off" the last word. You can do something like this:

    <mvt:eval expr="substring(g.shortdescrip,1,151)" />...

    So the last word will end like, "this is a desc..."

    Or in your case:

    <mvt:eval expr="substring(g.shortdescrip,1,87)" />...

    Hope this helps!
    M.A.D.* since 1997

    http://www.scotsscripts.com

    *miva application developers

    Comment


      #3
      That's exactly what I needed - thank you.

      Comment


        #4
        and if you don't want to cut a word in half,

        <mvt:assign name="l.thisString" value="substring(g.shortdescrip,1,87)" /> // get the first 87 characters
        <mvt:assign name="l.lastWordPos" value="' ' EIN l.thisString"/> // find the last space in the string
        <mvt:eval expr="substring(l.thisString, 1, l.lastWordPosition"/> // get everything Up to the last space



        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


          #5
          Thanks Bruce. Be nice to have a place to upload snippets like this.

          Comment


            #6
            https://snippets.miva.com/
            M.A.D.* since 1997

            http://www.scotsscripts.com

            *miva application developers

            Comment


              #7
              Okay I've never seen that site. I think we need to have a button in the forum header for this if any of the Miva mods see this. I'd recommend you guys add your solutions if you are willing as this seems to be something of general use. Thanks.

              Comment


                #8
                willing...time is another thing though :)
                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


                  #9
                  updating this thread. I wanted to start adding and also searching for snippets on snippets.miva.com but the login isn't working for me.

                  my snippet

                  <mvt:assign name="g.foo" value="'#this is my test text#'" />
                  &mvte:global:foo;<BR></BR>
                  <mvt:assign name="g.foo" value="substring(g.foo, 2, len(g.foo) - 2))" />
                  &mvte:global:foo;

                  to trip the first and last characters off a string.

                  Comment


                    #10
                    boo hoo snippets.miva.com is gone. where did it move too?

                    Comment

                    Working...
                    X