简体   繁体   English

从Smarty模板调用PHP

[英]Calling PHP from Smarty template

I am trying to integrate an ad package into my Smarty based site. 我正在尝试将广告包整合到我的Smarty网站中。 I have been given the following PHP code that I need to add to my footer file. 我已经获得了以下PHP代码,我需要将其添加到我的页脚文件中。 But due to it being Smarty I need to add the code instead to my php file so that it can be called/included in my Smarty template file. 但由于它是Smarty我需要将代码添加到我的php文件中,以便可以调用/包含在我的Smarty模板文件中。 This was the code that I was given and that I need to include: 这是我给出的代码,我需要包括:

    <?php if(function_exists('ad_footer')) ad_footer(); ?>

But in the php file I am not sure how to achieve this - I have got this example and wanted to know if it looked correct?? 但在php文件中我不知道如何实现这一点 - 我有这个例子,想知道它看起来是否正确?

if(function_exists('ad_footer')) {
 ob_start();
 ad_footer();
 $smarty->assign('ad_footer', ob_get_clean());

} }

Does the above look the right way to do it? 以上看起来是正确的方法吗?

Thanks in advance 提前致谢

我继续创建了一个测试页面,看看上面是否有效,但是这样做会坚持使用这段代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM