Here is an easy way to add multiple images
Archived from the Web Auction Discussion forum.
Nicole — Sun Dec 16, 2007 2:53 am
After much headbanging and unwillingness to really did into the code, I finally figured out how to EASILY have multiple images
-
Edit database to allow input of more images. Add new fields to the product table as ‘product_image_01’ ‘product_image_02’ etc using the same values as ‘product_image’ until you have the max number of images you want to add to each product. (Interestingly it works without adding additional image MIME type rows. I don’t know enough to address that or if they truly should be created.)
-
Edit the file tables/products/fields.ini file to add near the top of the file:
[product_image_01]
Type=container
allowed_extensions=”jpg,gif,png”
visibility:list = hidden
visibility:list = hidden
[product_image_02]
Type=container
allowed_extensions=”jpg,gif,png”
visibility:list = hidden
visibility:list = hidden
Repeat until you match the number of images you want.
- Edit this same file in tables/products/fields.ini file to add near the BOTTOM of the file:
[product_image_mimetype_01]
visibility:list = hidden
[product_image_mimetype_02]
visibility:list = hidden
etc
- Edit the file in templates/view_product.html template file to display these additional images. Because the forum is eating code, you’ll have to stretch a little to accomplish this step.
Locate and copy/paste line that starts the image display and repeat as necessary:
shannah — Sun Dec 16, 2007 9:13 pm
Thanks for posting this tutorial, Nicole. I’m sure it will be helpful to a lot of people.
A couple of notes:
(Interestingly it works without adding additional image MIME type rows. I don’t know enough to address that or if they truly should be created.)
Yes. It will work without adding the mimetype columns, but these columns will help dataface in various places to work more smoothly with the images as it will help it to know that they are, in fact, images.
Edit the file tables/products/fields.ini file to add near the top of the file:
…Edit this same file in tables/products/fields.ini file to add near the BOTTOM of the file:
It actually doesn’t matter whether you add these to the top or bottom of the file.
The app will not display broken image code if there isn’t an image uploaded for that row
This may have been a stroke of luck with your browser. A good way to check for nulls in your template is just to use an {if} tag.
e.g.
- Code: Select all
{if $record->val('product_image_01')} ... {/if}
Thanks and best regards
Steve
Nicole — Sun Dec 16, 2007 10:08 pm
Quote:
The app will not display broken image code if there isn’t an image uploaded for that row
This may have been a stroke of luck with your browser. A good way to check for nulls in your template is just to use an {if} tag.
e.g.
You’re right.. Was my browser (Firefox) degrading nicely. IE displayed broken images.
view_product.html file to check for images before displaying:
{if $record->val(‘product_image_01’)}
{/if}
{if $record->val(‘product_image_02’)}
{/if}
Thanks for that {if} code, Steve! Works like a champ!
Aloha,
Nicole
r0n2990 — Tue Dec 18, 2007 3:23 pm
Hey,
I love the code but I am trying to use it on the home page and its giving me an error about how it does not like it a null. The thing is I am using the same code that I used on the product page.
Any suggestions?
-Cam
r0n2990 — Tue Dec 18, 2007 6:07 pm
I figured it out,
- Code: Select all
- `{if $product->val(‘product_image’) != NULL}
…
{/if}`
That worked nicely for me.