Announcement

Collapse
No announcement yet.

Quicklist - Add a comma after each list item on display

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

    Quicklist - Add a comma after each list item on display

    I am building a quicklist on the product page with a comma separate list of related product codes. I need to be able to separate each list item with a comma on the page (as opposed to line breaks). I looked at the pos1 docs, but if my theory is correct, I will end up having a comma after the last item. How can I avoid that?

    #2
    Code:
    <mvt:foreach ...>
    <mvt:if expr="l.pos1 GT 1">
        ,
    </mvt:if>
    
    All your other code here...
    </mvt:foreach>
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      Originally posted by eldon99 View Post
      I am building a quicklist on the product page with a comma separate list of related product codes. I need to be able to separate each list item with a comma on the page (as opposed to line breaks). I looked at the pos1 docs, but if my theory is correct, I will end up having a comma after the last item. How can I avoid that?
      I was just working with the Toolkit Quicklist and was wondering if anyone had (or is) done (doing) something to replace it. In my concept, I'd like to be able to load the "quicklist" products into a custom field (so that the code on the page won't have to be tweaked each time an update is needed). I had been playing around with trying to use a custom product field in this

      Code:
      <mvt:item name="toolkit" param="quick|pcount|&mvt:customfield_values:customfields:madness;" />
      It may not have work because of the formatting I tried using.

      Anywho, I'm tagging along to see if I can glean some insight.
      Leslie Kirk
      Miva Certified Developer
      Miva Merchant Specialist since 1997
      Previously of Webs Your Way
      (aka Leslie Nord leslienord)

      Email me: [email protected]
      www.lesliekirk.com

      Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

      Comment


        #4
        Are you saying you have a custom field already populated with comma separated product codes, or are you trying to dynamically load product codes into a custom field on the page using template scripting?
        M.A.D.* since 1997

        http://www.scotsscripts.com

        *miva application developers

        Comment


          #5
          Originally posted by Scot - ScotsScripts.com View Post
          Are you saying you have a custom field already populated with comma separated product codes, or are you trying to dynamically load product codes into a custom field on the page using template scripting?
          Me?
          Leslie Kirk
          Miva Certified Developer
          Miva Merchant Specialist since 1997
          Previously of Webs Your Way
          (aka Leslie Nord leslienord)

          Email me: [email protected]
          www.lesliekirk.com

          Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

          Comment


            #6
            Yes :) I'm just not clear what your starting condition is. If the codes are already in the custom field then it would be easy to turn them into an array and use a foreach to roll through them.
            M.A.D.* since 1997

            http://www.scotsscripts.com

            *miva application developers

            Comment


              #7
              Originally posted by Scot - ScotsScripts.com View Post
              Yes :) I'm just not clear what your starting condition is. If the codes are already in the custom field then it would be easy to turn them into an array and use a foreach to roll through them.
              I'm currently using the Toolkit snippet to create a Quicklist. You have to go to the code in the template every time you want to update the products being displayed. I wanted to create a custom field that I could enter the product codes into it, then place that custom code into the Toolkit snippet which would, in turn, load the products to be displayed. I'm thinking that I cannot have something like &mvt:customfield_values:customfields:madness; within the Toolkit snippet.

              I'm tagging along on this thread to see if there is a much better way to do this that would allow me to use custom fields and mivascript instead of the Toolkit.

              Leslie Kirk
              Miva Certified Developer
              Miva Merchant Specialist since 1997
              Previously of Webs Your Way
              (aka Leslie Nord leslienord)

              Email me: [email protected]
              www.lesliekirk.com

              Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

              Comment


                #8
                Not sure of the particular here since i never used toolkit much, but, doesn't toolkit accept global variables? If so, just use the Product_Read() custom field function to create a global that can be read by toolkit.
                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
                  dcarver I just want to make sure I understand l.pos, wouldn't he want to avoid the comma at the end?

                  Code:
                   
                   <mvt:foreach ...>  All your other code here...  <mvt:if expr="l.pos1 NE miva_array_elements(array)" >,</mvt:if> </mvt:foreach>
                  (Good for building JSON)

                  Also, if you have nested loops, the inner loop becomes l.pos2 etc.

                  http://www.alphabetsigns.com/

                  Comment


                    #10
                    alphabet my code does avoid the comma at the end. We are outputting the comma BEFORE we output any data for the loop. So if we are on the last element, and the last element position isn't one, we output a comma so it goes <element>,<last_element> where the comma and <last_element> all occur in the last iteration of the loop.
                    David Carver
                    Miva, Inc. | Software Developer

                    Comment


                      #11
                      Got it.

                      Thank you for the explanation and your code evaluates faster.
                      http://www.alphabetsigns.com/

                      Comment


                        #12
                        dcarver, thank you for that code. The one thing is that I cannot figure out how to avoid a space before the comma.

                        Comment


                          #13
                          You'd could probably use an mvt:capture to and then only use mvt:evals inside of the capture? Otherwise you'd probably need to use <mvt:miva output="off" /> and then do <mvt:eval /> all the other data. <mvt:capture> may also work.
                          David Carver
                          Miva, Inc. | Software Developer

                          Comment

                          Working...
                          X