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

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Charlie
Forum Members
Forum Members
Posts: 18
Joined: Sun Feb 07, 2010 6:59 pm

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

Post 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?
Last edited by Charlie on Mon Feb 15, 2010 10:52 pm, edited 1 time in total.
Charlie
Forum Members
Forum Members
Posts: 18
Joined: Sun Feb 07, 2010 6:59 pm

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

Post 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.
Post Reply

Return to “Modules/Add-Ons”