标签: smarty

如何在Smarty中定义具有随机值的变量

我需要分配一个变量,用于为某些html元素创建id标签.

它需要是独一无二的.

我试过了

{assign var=unique_id value=`10|mt_rand:20`}
Run Code Online (Sandbox Code Playgroud)

{math equation='rand(10,100)'}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何使用结果

我没有任何其他想法

html smarty

10
推荐指数
1
解决办法
1万
查看次数

如何使smarty的显示函数返回变量

在smarty中是否有可能或有任何类型的函数来呈现模板并返回结果?

例如:

$rendered_content = $smarty->render("content.html")
Run Code Online (Sandbox Code Playgroud)

php smarty

10
推荐指数
1
解决办法
6073
查看次数

Ajax如何加载一些脚本

我有以下代码,加载到未读取的列表内容,具体取决于信息的跨度:

$(document).on('click','#addplaylisttolist',function(){
    myPlaylist.pause();
    myPlaylist.remove();
    $("#playlist_selected_songs").empty();
    $.each($(this).find("span"),function(){
            $("#playlist_individual_li").load('listen_playlist_section_content_item_add',{musicId:$(this).attr('data-id-music'),musicTitle:$(this).attr('data-title'),musicArtist:$(this).attr('data-artist'),musicFile:$(this).attr('data-mp3'),musicPoster:$(this).attr('data-poster'),musicTime:$(this).attr('data-time-music')},function(){
                $("#playlist_selected_songs").append($("#playlist_individual_li").html());
            });
        });
    myPlaylist.play();
});
Run Code Online (Sandbox Code Playgroud)

将构建播放列表的代码:

    <div class="m-t-n-xxs item pos-rlt">
        <div class="top text-right">
            <span class="musicbar animate bg-success bg-empty inline m-r-lg m-t" style="width:25px;height:30px">
                <span class="bar1 a3 lter"></span>
                <span class="bar2 a5 lt"></span>
                <span class="bar3 a1 bg"></span>
                <span class="bar4 a4 dk"></span>
                <span class="bar5 a2 dker"></span>
            </span>
        </div>

        <div id="playlist_owner_info" class="bottom gd bg-info wrapper-lg">
            <span id="playlist_owner_info_followers" class="pull-right text-sm">
                            {$item.profile_jrFollower_item_count}
                            <br>
                            Followers
            </span>
            <span id="playlist_owner_info_name" class="h2 font-thin">
                            {$item.profile_name}
            </span>
        </div>
        {jrCore_module_function function="jrImage_display" module="jrProfile" type="profile_image" id="playlist_owner_img" class="img-full halfwidth" item_id=$item.profile_id …
Run Code Online (Sandbox Code Playgroud)

html ajax jquery smarty sharethis

10
推荐指数
1
解决办法
320
查看次数

查找在PHP(和/或SMARTY)中定义变量的位置?

我目前正在开展一个非常大的项目,并且很快就要完成它,并且我遇到了严重的问题.编程最后以非常奇怪的方式编写变量的程序员 - 配置变量并非都在同一个文件中,它们分布在整个项目中,包含500多个文件和100k +代码行,而我正在一时间弄清楚某个变量在哪里,所以我可以解决一个问题.
有没有办法跟踪这个变量?我相信他正在使用SMARTY(由于这样的问题我无法忍受),变量是模板变量.我很确定我正在寻找的变量最初被定义为PHP变量,然后该变量被传递到SMARTY,所以我想跟踪PHP一个,但是如果这是不可能的 - 我该如何跟踪在他为SMARTY定义变量的地方?

PS我在Vista中,并没有ssh访问服务器,所以'grep'是不可能的.

php variables definition smarty

9
推荐指数
3
解决办法
1万
查看次数

Smarty获取var的子字符串,其中strpos为start,strlen为end

我在smarty中遇到格式化变量问题.我想知道最好的方法是什么.基本上我有一个字符串"ABC | DEFGH"我想要聪明地获得"DEFGH"的子串我将如何去做这个?

{$var|substr:strpos:"|":strlen}
Run Code Online (Sandbox Code Playgroud)

不起作用

php smarty smarty2

9
推荐指数
2
解决办法
3万
查看次数

纯PHP/HTML视图VS模板引擎视图

我想知道哪种方法更快,在HTML文件中使用纯PHP或使用像Smarty,Twig这样的模板引擎......我特别想知道的是下一个:解析得更快,是Smarty缓存比使用纯PHP更快?哪个模板引擎最快?我即将重写简单的应用程序,其中速度是第一位的.

html templates smarty twig

9
推荐指数
4
解决办法
1万
查看次数

我应该像Yii一样使用带有MVC的smarty模板引擎吗?

我过去使用过smarty,在x-cart,jobberbase和Joomla的jomestate组件以及其他一些Joomla组件中也是如此.我看到X-cart中的东西非常紧密,许多事情似乎比在jobberbase中应该更复杂,我觉得这是因为聪明.

现在我将在客户建议的项目中使用Yii.而Yii本身就是MVC框架.那么我应该使用smarty吗?我想知道我应该使用smarty,我的意思是在Yii中会有一些使用smarty的优点吗?或不?或者它只是一个开销还是会有一些使用smarty的缺点?我理解聪明.但我认为这有时会让事情变得更复杂.所以我想从你们这里知道,由于框架不好或者存在一些现实,这只是一个主导思想,所以我应该使用smarty还是还有其他更好的东西呢?

template-engine smarty yii

9
推荐指数
1
解决办法
6711
查看次数

Smarty PHP与AngularJS发生冲突

当我在同一模板中使用AngularJS时,如何阻止Smarty抛出错误.我有一个包含此代码的Smarty页面模板:

 <li ng-repeat="i in items">
      <p class="item">{{i}}</p>
 </li>
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中查看时,我得到一个空白页面.我的apache error_log中出现了一个很大的错误,其中包含以下内容:

 PHP Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template ... <p>{{i}}</p>; unknown tag "i
Run Code Online (Sandbox Code Playgroud)

如果我将{{i}}替换为{{4}}或任何其他数字,则可以正常工作.我也可以使用数学,{{8 + 2}}将在页面中显示10.这是Smarty做angularJS的数学吗?

javascript php template-engine smarty angularjs

9
推荐指数
2
解决办法
7461
查看次数

smarty for loop无法识别的标签

我今天刚刚开始使用Smarty,所​​以我可能完全错了,但我似乎无法找到问题的解决方案.我试图让for循环迭代4次,每次迭代增加$ i.很标准的东西.

根据Smarty文档,for循环应该是以下形式:

{for $var=$start to $end}
Run Code Online (Sandbox Code Playgroud)

我当前的循环语句如下:

{for $i=0 to 3}
Run Code Online (Sandbox Code Playgroud)

但是我在运行时收到以下错误:

致命错误:Smarty错误:[in ..views/landing/index.tpl第69行]:语法错误:无法识别标签'for'(Smarty_Compiler.class.php,第590行)in ../library/1.11/Smarty/Smarty 1093行的.class.php

循环在第69行,这是编译器失败的行.我还缩短了该错误消息中的URL以便于阅读.

我不确定我在这里做错了什么.我试过谷歌搜索错误信息的各个部分,但无济于事.

谢谢你的时间.

for-loop smarty

9
推荐指数
1
解决办法
7821
查看次数

如何在iframe的"srcdoc"属性中设置HTML代码?

<div id="email_content">
<iframe srcdoc="{$email_content}"></iframe>
</div>
Run Code Online (Sandbox Code Playgroud)

如下图所示我在内部使用iframe div#email_content来显示电子邮件内容的准确预览.我正在尝试使用srcdoc属性来加载iframe中的电子邮件内容.这里的电子邮件内容可能是通过CkEditor设计的纯文本或HTML内容.我尝试使用转义,htmlentities等.但srcdoc属性中断,因为属性值包含纯HTML代码和引号.

任何解决方案都将被接受.

谢谢!

注意:我不想在src这里使用属性.

在此输入图像描述

php iframe smarty

9
推荐指数
2
解决办法
1486
查看次数