2014-09-26 66 views
0

我得到了一个脚本,并且Page的内容被放入home.tpl。从远程URL获取文件内容到Smarty模板

现在我想是这样的:

Text Text Text "value of php file" Text Text Text...

我的PHP文件是:

<?php 
    $btc4cents = file_get_contents("https://blockchain.info/tobtc?currency=USD&value=0.04"); 
?> 

我已经tryed这么多已经添加它。与{} PHP的标签,以创建一些文件与此代码:

<?php 
    function smarty_function_btc(array $params, Smarty_Template_Instance) { 
     include 'btc.php'; 
    } 
?> 

,然后使它像

Text Text Text {btc} text text text...

但我只得到错误...

回答

1

可以使用fetch Smarty的功能:

{* assign the fetched contents to a template variable *} 
{fetch file='https://blockchain.info/tobtc?currency=USD&value=0.04' assign='btc'} 

然后执行:

Text Text Text {$btc} text text text... 

检查documentation.

+0

谢谢你的回答。我必须说,我是一个绝对聪明的noob ..我在哪里添加: {*将获取的内容分配给模板变量*} {fetch file ='https://blockchain.info/tobtc?currency = USD&value = 0.04'assign ='btc'} – Jerome 2014-09-26 20:50:44

+0

@Jerome很好,因为你使用Smarty,你有'home.tpl',那么你应该在那里显示它.. – takeit 2014-09-26 21:16:30

+0

谢谢!很棒!我可以直接问你另外一个问题吗?我在这里有一些价值:{$ statistics.cashout},我可以如何发送这个值到链接?就像{fetch file ='https://blockchain.info/tobtc?currency = USD&value = {$ statistics.cashout}'assign ='btc'} ...我已经尝试过了,但只会给出错误!再次感谢 – Jerome 2014-09-26 21:23:11