Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty "if" statements with custom functions

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
omarswan
Smarty Rookie


Joined: 17 May 2003
Posts: 5

PostPosted: Sat May 17, 2003 1:43 am    Post subject: smarty "if" statements with custom functions Reply with quote

Hi guys,
I put together a simple smarty function to check if a local
file exist. the code is below:

Code:

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.file_exists.php
 * Type:     function
 * Name:     file_exists
 * Purpose:  checks if a file exist
 * -------------------------------------------------------------
 */
function smarty_function_file_exists($params, &$smarty)
{

    extract($params);

    if (empty($file)) {
        $smarty->trigger_error("assign: missing 'file' parameter");
        return;
    }

    return file_exists($file);
}
?>


now...

Is there a way to include this in the a smarty template file (template.tpl).

Here the idea!

Quote:

{assign var="file" value="test.tpl"}

{if !file_exists($file) }
File Not Found!
{/if}



is there a way to get this done within a smarty template file?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat May 17, 2003 10:41 pm    Post subject: Reply with quote

If you rewrite this as a Smarty modifier, then you can have your template code look like this:

Code:
{if $file|file_exists}
    File Exists
{/if}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP