[solved] FEUser - checking if an image has been set?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
Gillian.Hesse
Forum Members
Forum Members
Posts: 37
Joined: Thu Nov 08, 2007 1:29 pm
Location: Nijmegen, NL

[solved] FEUser - checking if an image has been set?

Post by Gillian.Hesse »

Hi there,

I have an optional image property defined in Front end user.  I need to check in my smarty templates whether this property has been set when displaying the user info, but haven't managed to do this successfully.  I'll give an example.  Assuming the smarty variable is called $photo I tried

Code: Select all

{if $photo==""}
    <img src="{$gCms->config.uploads_url}/feusers/{$photo}" alt="no photo available"/>
{else}
    <img src="{$gCms->config.uploads_url}/feusers/defaultuser.jpg" alt="no photo available"/>
{/if}
I thought this should be the right test as {$photo|print_r} returns the filename when the photo has been set and nothing when it hasn't.

The problem is that even when no photo has been set the {if photo==""} returns true and the html source produced contains

Code: Select all

<img src="my_root_url/feusers/<noset>" alt="no photo available"/>
But {if noset($photo)} does not work either as the variable is actually set.

I would appreciate any ideas how to check this.

Thanks

Gillian
Last edited by Gillian.Hesse on Mon May 19, 2008 7:30 pm, edited 1 time in total.
User avatar
Gillian.Hesse
Forum Members
Forum Members
Posts: 37
Joined: Thu Nov 08, 2007 1:29 pm
Location: Nijmegen, NL

Re: FEUser - checking if an image has been set?

Post by Gillian.Hesse »

Finally solved the problem.  But it is defiantly strange. 

When an image upload property has not been set the filename is set to the string ''.  So in my example the variable $photo=="".  When you print the variable using {$photo} nothing appears, which made me think it was am empty string, but if you look at the html source code the is there, it just isn't displayed by the browser (firefox).  The color syntax of the in the source suggests it is an html contruct, but I can not find any documentation for it.  As I said - strange.

so the solution is to check if the variable equals "" rather than looking for an empty string.

Code: Select all

{if $photo=="<notset>"}
    <img src="{$gCms->config.uploads_url}/feusers/{$photo}" alt="no photo available"/>
{else}
    <img src="{$gCms->config.uploads_url}/feusers/defaultuser.jpg" alt="no photo available"/>
{/if}
Post Reply

Return to “Modules/Add-Ons”