Announcement

Collapse
No announcement yet.

sexists for multiple file extensions

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

    sexists for multiple file extensions

    Hi,

    I am currently using the sexists function below to check to see if we have a customer photo on file. The only problem I am having is I need it to check for several file extensions instead of just ".jpg". I wanted to have it check for .bmp, .png, .tif as well.

    <mvt:item name="toolkit" param="sassign|filename|/images/customers/photo/%photo_name%_photo.jpg" />
    <mvt:item name="toolkit" param="vglosub|filename,%photo_name%,g.basket:cust _id" />
    <mvt:item name="toolkit" param="sexists|vpath|filename" />
    <mvt:if expr="vpath GT 0">
    Use my photo on file from my previous order.
    <input type="hidden" name="Product_Attributes[ 43 ]:code" value="BCG" />
    <input type="hidden" name="Product_Attributes[ 43 ]:template_code" value="Phonfile" />
    <input type="hidden" name="Product_Attributes[43]:value" value="&mvt:global:basket:cust_id;_photo.jpg">
    <mvt:else>
    We currently do not have a photo on file for you.
    </mvt:if>


    Thanks,
    Mike

    #2
    Re: sexists for multiple file extensions

    I haven't tested this code, but something along these lines should work. You can create an array with the extensions and loop though them.

    Also, your code uses toolkit functions, but all this can be done with built in functions and mvt:assign (assuming your store is on the latest engine)

    Code:
    <mvt:assign name="g.imagetype[1]" value=" '.jpg' " />
    <mvt:assign name="g.imagetype[2]" value=" '.bmp' " />
    <mvt:assign name="g.imagetype[3]" value=" '.png' " />
    <mvt:assign name="g.imagetype[4]" value=" '.tif' " />
    
    
    <mvt:assign name="g.filepath" value="'/images/customers/photo/' $ g.basket:cust_id $ '_photo'" />
    
    
    <mvt:foreach iterator="extention" array="global:imagetype">
        
        <mvt:assign name="g.image_exists" value="sexists(g.filepath $ l.settings:extention)" />
    
    
        <mvt:if expr="g.image_exists EQ 1">
            <mvt:assign name="g.image_name" value="g.basket:cust_id $ '_photo' $ l.settings:extention" />
        </mvt:if>
    
    
    </mvt:if>
    
    
    
    
    <mvt:if expr="NOT ISNULL g.image_name">
        The Image Name is: &mvt:global:image_name;
    <mvt:else>
        No Image Exists
    </mvt:if>
    Last edited by Brennan; 07-09-14, 11:58 AM.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: sexists for multiple file extensions

      Hi Brennan,

      Thanks for getting back to me. I've been playing with the code but still learning so bare with me. When I use that I get:
      syntax error, unexpected IF, expecting FOREACH

      Mike

      Comment


        #4
        Re: sexists for multiple file extensions

        Change
        </mvt:if>
        to
        </mvt:foreach>
        to close the foreach loop.
        Last edited by wcw; 07-13-14, 06:19 AM.
        Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
        Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
        Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
        Facebook http://www.facebook.com/EmporiumPlus
        Twitter http://twitter.com/emporiumplus

        Comment


          #5
          Re: sexists for multiple file extensions

          Thanks Bill, that fixed it for me.

          Mike

          Comment


            #6
            Re: sexists for multiple file extensions

            The extensions portion in the array is working perfect, but when the file does not exist I'm still getting "The Image Name is:" with a crashed image. I assume I don't have the conditional correct below?


            <mvt:assign name="g.imagetype[1]" value=" '.jpg' " />
            <mvt:assign name="g.imagetype[2]" value=" '.bmp' " />
            <mvt:assign name="g.imagetype[3]" value=" '.png' " />
            <mvt:assign name="g.imagetype[4]" value=" '.tif' " />

            <mvt:assign name="g.filepath" value="'/images/customers/photo/' $ g.basket:cust_id $ '_photo'" />
            <mvt:foreach iterator="extention" array="global:imagetype">
            <mvt:assign name="g.image_exists" value="sexists(g.filepath $ l.settings:extention)" />
            <mvt:if expr="g.image_exists EQ 1">
            <mvt:assign name="g.image_name" value="g.basket:cust_id $ '_photo' $ l.settings:extention" />
            </mvt:if>
            </mvt:foreach>
            <mvt:if expr="NOT ISNULL g.image_exists">
            The Image Name is: &mvt:global:image_name;
            <img src="/images/customers/photo/&mvt:global:image_name;" width="200" border="0" />
            <mvt:else>
            No Image Exists
            </mvt:if>

            Comment


              #7
              Re: sexists for multiple file extensions

              Not sure where this data is coming from, but I note that "extension" is misspelled.
              Kent Multer
              Magic Metal Productions
              http://TheMagicM.com
              * Web developer/designer
              * E-commerce and Miva
              * Author, The Official Miva Web Scripting Book -- available on-line:
              http://www.amazon.com/exec/obidos/IS...icmetalproducA

              Comment


                #8
                Re: sexists for multiple file extensions

                Thanks Kent, I corrected that. Still having an issue with this part not working for me:

                <mvt:if expr="NOT ISNULL g.image_exists">
                The Image Name is: &mvt:global:image_name;
                <img src="/images/customers/photo/&mvt:global:image_name;" width="200" border="0" />
                <mvt:else>
                No Image Exists
                </mvt:if>

                Comment

                Working...
                X