ThinkPHP’s built-in template engine is quite good, but when existing websites are already built with Smarty and you want to use the TP (short for ThinkPHP) framework without TP’s own template engine, this naturally leads to TP’s support for third-party libraries. However, while the concept exists, the actual method of importing libraries was still unknown, so I searched on Baidu. There aren’t many articles and tutorials about TP online, but I found one article on TP’s official website that sparked some inspiration! See the original article: http://www.thinkphp.cn/Blog/2. Below I’ve excerpted some useful parts. Take a look:
Using Smarty as an example, you just need to set the following in your project configuration file:
PHP code
‘TMPL_ENGINE_TYPE’=>’smarty’
This allows you to use Smarty template tags in your template files. If you want to configure Smarty parameters further, you can use the following configuration:
PHP code
‘TMPL_ENGINE_CONFIG’=>array(
‘caching’=>true,
‘template_dir’=>TMPL_PATH,
‘compile_dir’=>CACHE_PATH,
‘cache_dir’=>TEMP_PATH
)
Alright! Now let me walk you through the specific steps!
First, download Smarty from the official Smarty website.
Next, extract the archive, which contains two folders: demo and libs. Open the libs folder and copy all its contents.
Next, open the thinkphp folder in your website’s root directory. Inside there is a vendor folder — this is the folder TP uses for third-party libraries. Paste everything you just copied into it.
Then, open your project’s configuration file, which should be conf.php in your project’s conf directory.
Add the following configuration:
‘TMPL_ENGINE_TYPE’=>’Smarty’
If you want more configuration options, you can also add:
‘TMPL_ENGINE_CONFIG’=>array(
‘caching’=>true,
‘template_dir’=>TMPL_PATH,
‘compile_dir’=>CACHE_PATH,
‘cache_dir’=>TEMP_PATH
)
Now you can use Smarty templates.
The template file location and cache location remain unchanged.