Your Open Source

 
Related Links
PHP  >>  Smarty

Smarty

Creating Custom function or tag in Smarty templates

Smarty in-build a lot of function to customize the pages that we want.. the following ways to we can make a new custom function or tags,

Step 1 :-
Need to write the php function in the smarty plug-ins directory,


function smarty_function_sitehost($params, &$smarty){
if(!isset($params['key'])) {
$smarty->trigger_error("Invalid ID");
return;
}

return $_SERVER["HTTP_HOST"];
}

need to save the files like this style function.sitehost.php and stored in plugins directory.

Step 2:-

In smarty template files, name is home.tpl
 {sitehost key='ghost'}  


This is normal smarty templates files, so can call the sitehost smarty tag whenever needed.
That's it.

  • hits 100
  • datetime Jul 03 09 06:31:44
  • author Sekar
  • rating

Rating : 12345

Comments

No Reply..

Quick Reply or Comments

Preview
Your Name:
Your Reply :
<> is a code tag
Enter the verification code: