Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto load a smarty plugin

Tags:

php

smarty

We have a plugin for a PHP script with Smarty template engine,

It can be used in template files with {plugin_name} but that requires making sure this is on every single template file, the question is:

is there a way to auto-load this plugin whenever the scripts loads?

Script is not open source, but Smarty and it's files (such as Smarty.class.php etc) are not encrypted.

Edit

All I need to do is to auto-load a Smarty Plugin (which has small interaction with database) before template files load, is this possible/achievable with Smarty files only? (script itself in encrypted, but Smarty_Compiler.class.php, Smarty.class.php, Config_File.class.php, and other smarty core functions are open source)

like image 473
Vladimir Avatar asked Aug 25 '16 05:08

Vladimir


1 Answers

It depends on the Smarty version you're using.

With Smarty 3 you can do :

$smarty = new Smarty();
$smarty->setTemplatesDir(....);
$smarty->addPluginsDir('/path/to/your/plugins');
... stuff.
$smarty->display('template.tpl');

See also: https://www.smarty.net/docs/en/api.add.plugins.dir.tpl

With Smarty2 I think you need to do something more like this -

https://www.smarty.net/docsv2/en/api.register.function.tpl

Or, you drop your function into the libs/plugins directory with the right file name and function name ...

like image 74
David Goodwin Avatar answered Nov 04 '22 23:11

David Goodwin