Smarty: checking for a file

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Smarty: checking for a file

Post by yellowled »

Maybe I'm too stupid to follow the Smarty docs correctly, maybe it's just too early. Is there any way to check in a .tpl file whether a certain file (i.e. an image at a given location) exists at all?

YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Smarty: checking for a file

Post by garvinhicking »

Hi!

No, the getFile check always falls back to the default name you submitted.

Can you describe the scenario you need that check for? In the past, such a function was not really needed.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Smarty: checking for a file

Post by yellowled »

garvinhicking wrote:Can you describe the scenario you need that check for? In the past, such a function was not really needed.
I'm working on a port which has a different start page than we usually have. It displays a certain category as "lead articles", another one as "features", and a third as "news", all of them as "teasers". All of these have an image associated with them which is not included in the entry. It's only shown on the index page.

My current approach to implement this is to make users upload images with the filename {$entry.id}.jpg to a selected directory, and it would be nice - although not actually necessary - to check whether the image to be included is actually present or not.

Of course, I'm open to other suggestions to implement this feature, maybe even using the media database, which would be the most comfortable way for users anyway.

YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Smarty: checking for a file

Post by garvinhicking »

Hi!
My current approach to implement this is to make users upload images with the filename {$entry.id}.jpg to a selected directory, and it would be nice - although not actually necessary - to check whether the image to be included is actually present or not.
How about using custom entrproperties for that? A field with "news_image", "bla_image", "bla_image2" into which a user can pick a media database image? Then those fields are only filled if an image was entered. This also makes it unneccessary for people to upload images via FTP?

Apart from that, developing an event plugin would be the better way to go, then you could also easier define default images (maybe depending on the associated category, or whatever).

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Smarty: checking for a file

Post by yellowled »

garvinhicking wrote:How about using custom entrproperties for that? A field with "news_image", "bla_image", "bla_image2" into which a user can pick a media database image? Then those fields are only filled if an image was entered. This also makes it unneccessary for people to upload images via FTP?
Sounds great. I'll look into that tomorrow.
garvinhicking wrote:Apart from that, developing an event plugin would be the better way to go, then you could also easier define default images (maybe depending on the associated category, or whatever).
Well, first of all: I may have svn access, but I'm still no PHP coder :wink: Second, that would require people to have said plugin installed. Plus, why code another plugin if the funtionality is possibly already there?

I'll see what I can do using custom entry properties first.

YL
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Post by yellowled »

Whoa. That's a lot better than my approach to it :)

It's working great with a custom entry property - of course users will have to have the extended entry properties plugin installed and define the custom field themselves, but I figure that will be okay. I'll add an instructional text to the theme options, and people using this template will have to put in some more "extra work" to use it anyway, so it's fine.

Definitely no need to code an extra plugin providing the same functionality in my humble opinion, and thanks again, Garvin! :)

YL
Post Reply