Page 1 of 1

[solved] Put {sectionimage} in a conditional statement to check if image exists

Posted: Wed Feb 10, 2010 4:57 am
by Charlie
If you include {sectionimage} on a page and image does not exist CMSMS will create a blank box where the picture should go.

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 I don't want to show the blank box. I have tried the following but it does not seem to work:

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

The image will produce fine if I don't have the {if $sectionimage ne ''} there, but as it is written it will not work.

Can anybody offer any suggestions? Would there be another way to check and see if a filename exists based on the Alias of the present page?

Re: Want to put {sectionimage} in a conditional statement to check if image exists

Posted: Mon Feb 15, 2010 10:51 pm
by Charlie
Ajprog was nice enough to help me out with a solution to this problem which was much easier than what I had originally suggested:

This code will put an image on each page providing an image exists in the uploads/images/pages directory. For instance, if there is a page with the alias "history" and this code is included in the template then an image will appear providing there is an image history.jpg included in the uploads/images/pages directory.

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

{/if}

I hope somebody else might find this code useful.