如何将PHP代码添加到.tpl文件 [英] How to add PHP code to .tpl file

查看:114
本文介绍了如何将PHP代码添加到.tpl文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示一些从php文件到.tpl文件的外部数据.为此,我想将php文件包括到.tpl文件中.我尝试过下面的代码将php文件的内容显示到tpl.

I need to display some external data from php file to .tpl file. For this I want to include php file to .tpl file. I have tried folllowing code to display php file content to tpl.

{php} include('custom_code.php'); {/php}

,但页面输出为include('custom_code.php');

推荐答案

{php}已弃用.看看使用插件扩展Smarty .

将以下内容放入…/plugins/function.yourplugin.php:

<?php
function smarty_function_yourplugin(array $params, Smarty_Template_Instance) {
    include 'your_other_file.php';
}

并在您的模板中使用:

{yourplugin}

这篇关于如何将PHP代码添加到.tpl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆