How can I use such statement in smarty?

女生的网名这么多〃 提交于 2019-12-11 06:55:05

问题


{assign var=tmp_url value=setURI(array('page' => 1))}

It seems array() can't be used in smarty ?

I tried various ways ,but none work.

Anyone knows the trick?


回答1:


try this,

In php file, write a function

<?php
 function getSetUri(){
   return setURI(array('page' => 1));
 }
?>

In template file, just call the function

{assign var=tmp_url value=getSetUri()}



回答2:


as far as I can tell there is no native way of setting an array in smarty you could assign the array to smarty templete in your php and call it page

then accesss it in smarty like this

 {assign var=tmp_url value=setURI($page[1])}

or you could use a plug in. there are some other options in this thread but I'm not sure what will be best for you. you may need to find another way of doing what you want or modifying your function in some way so it can take a string




回答3:


You could use {php} tags to assign the variable value in there:

<h1>Foo!{$var}</h1>
{php}
$this->assign('tmp_url', setURI($page[1]));
{/php}
<a href={$tmp_url}">bar</a>


来源:https://stackoverflow.com/questions/5605693/how-can-i-use-such-statement-in-smarty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!