[solved] Need simple debugging help for new function

Talk about new features for CMSMS and modules.
Post Reply
Charlie
Forum Members
Forum Members
Posts: 18
Joined: Sun Feb 07, 2010 6:59 pm

[solved] Need simple debugging help for new function

Post by Charlie »

I recently completed a website with 50 different pages. I would like to put different images on each of those pages but the images don't exist yet. What I would like to do is create a script which will go into the template for the website and check to if a image exists for that page. If it does load it, if not don't load anything.

For example, for the page with an alias "products", if the file products.jpg exists then a image will appear. If it is not there (yet) then nothing will appear. This way images could be added to the site just by uploading them to the server. They would appear automatically.

I have an idea for a modification of the {sectionimage} which I would like some help with. If you include {sectionimage} on a page and image does not exist CMSMS will create a blank box where the image should go. This is what I'd like to change.

I would like to put the Tag {sectionimage} in a conditional statement to see if the image does indeed exist. If it does I would like to show the image. If it does not exist nothing should appear - I don't want to show the blank box. I have tried the following code but it does not seem to work:

{if $sectionimage ne ''}
{sectionimage lowercase=1 levels=2 byname=1 image_path=uploads/images/page}
{/if}

The above code does not work. Can somebody please help me correct it?

Would there be another way to check and see if a filename exists based on the Alias+".jpg" exists on the server?
Last edited by Charlie on Mon Feb 15, 2010 10:45 pm, edited 1 time in total.
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Need simple debugging help for new function

Post by Jeff »

just use http://php.net/manual/en/function.file-exists.php

{capture assign=page_image}uploads/images/{$page_alias}.jpg{/capture}
{if file_exists($page_image)}

{/if}
Charlie
Forum Members
Forum Members
Posts: 18
Joined: Sun Feb 07, 2010 6:59 pm

Re: Need simple debugging help for new function

Post by Charlie »

Ajprog Thank You!

Except that there was just one small problem - quotes are required around the image name:

{capture assign=page_image}uploads/images/pages/{$page_alias}.jpg{/capture}
{if file_exists($page_image)}

{/if}

This works like a charm! I hope somebody else finds it valuable.
Post Reply

Return to “Feature ideas”