Your Open Source

 
Related Posts
PHP  >>  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 221
  • datetime Jul 03 09 06:31:44
  • author Sekar
  • rating

Rating : 12345
Tags :- Smarty

Answers

No Answers..
Your Name:
Your Answers :
<> is a code tag
Preview
Enter the verification code: