|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
omarswan Smarty Rookie
Joined: 17 May 2003 Posts: 5
|
Posted: Sat May 17, 2003 1:43 am Post subject: smarty "if" statements with custom functions |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat May 17, 2003 10:41 pm Post subject: |
|
|
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 |
|
|
|
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
|