标签: smarty3

使用smarty从字符串中删除空格

我很聪明.

我想知道如何从Smarty中的给定字符串中删除所有空白字符?

我有一个字符串,如"这是我的字符串".输出应该是"thisismystring".

我怎样才能做到这一点?

php string smarty smarty3

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

用 SMARTY + PHP 将 CSS 部分放在一起

如何完全分离css文件

我正在考虑如何将 CSS 部分放在 Smarty + php 生成的 html 文件中。CSS 应该包含在标题中,但是如果页面确实有一些单独的 CSS 样式怎么办?

我使用模板引擎 Smarty。首先,我制作了标题(收集所有常用的东西。)并使用聪明的语法将其包含在 html 文件的开头。如果页面中有 css 的某些单独部分,我会将 css 放在“include 语句”下方。

带有 Smarty 语法的 HTML 文件

{include file='_include/header.inc.html'}

    <link rel="stylesheet" href="/assets/style/top.css">
    <script type="text/javascript">
        $(function(){
            $('#eyecatch ul').bxSlider({
                pager: false,
                auto: true,
                pause: 5000
            });
        })
    </script>
    <article>
    </article>

{include file='_include/footer.inc.html'}
Run Code Online (Sandbox Code Playgroud)

但是我的同事检查了用 Smarty 生成的代码,并说“这不是一个好习惯,因为即使有效也应该放在一个地方”

标题正下方,因为我没有将此行放在标题中。

正如他指出的那样,您有什么好主意可以用 Smarty 清理/组织我的代码吗?

html css php smarty smarty3

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

Smarty:如何修复“未知修饰符‘重写’”异常?

将 Shopware 从 5.2 升级到 5.3 后,出现以下异常:

Smarty:未知修饰符“重写”

错误发生在模板文件中。显然,“重写”修饰符已被删除。我如何在模板文件中替换它?

{* Product image - uses the picture element for responsive retina images. *}
<a href="{$sArticle.linkDetails|rewrite:$sArticle.articleName}"
   title="{$sArticle.articleName|escape}"
   class="product--image" style="background-image: url('{if $sArticle.image.thumbnails[1].source}{$sArticle.image.thumbnails[1].source}{else}{link file='frontend/_public/src/img/no-picture.png'}{/if}')">
{*    <div class="product-hover">
        <span>Auge</span>
        <span>Details</span>
    </div>*}
Run Code Online (Sandbox Code Playgroud)

php smarty smarty3 shopware

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

如何关闭Smarty中的html转义

html_checkboxes用于生成选择菜单.问题是在复选框名称中我有一些HTML代码,Smarty逃脱了它.

我有:

{html_checkboxes name='select_menu' values=$user_data[1] output=$user_data[2]}
Run Code Online (Sandbox Code Playgroud)

我明白了:

Status: <span style="color: blue">Normal</span>
Run Code Online (Sandbox Code Playgroud)

我需要的状态只是蓝色.

php smarty3

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

Smarty:获取当前的物理文件路径

在Smarty中,有没有办法检索模板文件的当前物理路径?

我正在寻找与PHP相当的Smarty __FILE__超级变量.

(我敢肯定以前一定会问过这个问题,但我不能为我的生活找到它.或者也许有一个很好的理由没有被问到!?)

php smarty smarty3

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

使用Smarty模板切换和案例?

我是聪明的新手.我正在尝试使用智能的开关和案例功能.这是我使用的PHP代码

$i=1;
while ($row = mysqli_fetch_array($sql)){

    switch($i%8){

            case 1:
            case 2:
                //DO Something Here
            break;
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 0:
                //DO Something Else Here
            break;
        }
    $i++;

    }
Run Code Online (Sandbox Code Playgroud)

我的问题是如何将此代码应用于Smarty?感谢你的时间.

php smarty smarty3

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

将智能模板返回到html文本框

我想使用smarty将一些html返回到我网站后端的文本框中.我已经使用smarty来渲染后端了.

什么是最好的方法呢?

我以通常的方式将单个数组分配给smarty,但不确定如何返回模板.

php smarty smarty3

2
推荐指数
1
解决办法
1478
查看次数

你如何让Smarty3与Symfony2合作?

我正在尝试让Smarty 3作为Symfony 2的模板引擎.我正在尝试安装此捆绑包以使smarty 3工作:

https://github.com/noiselabs/SmartyBundle

它安装得很好,但是当我按照安装说明中的说法将它添加到AppKernal时,我收到以下错误:

致命错误:第20行的> /home/kevin/workspace/Symfony/app/AppKernel.php中找不到类'NoiseLabs\Bundle\SmartyBundle'

其中第20行在registerBundles()中:new NoiseLabs\Bundle\SmartyBundle(),

第二个可能相关的问题是在app/config/config.yml中,如果我在模板引擎数组中添加'smarty':

templating:      { engines: ['twig'] }
Run Code Online (Sandbox Code Playgroud)

它会抛出此错误:

ServiceNotFoundException:服务"模板化"依赖于不存在的>服务"templating.engine.smarty".

我意识到twig带有symfony但是对于这个项目我需要使用smarty.我错过了什么或是否有其他解决方案?

这是内核代码:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {   
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
//new NoiseLabs\Bundle\SmartyBundle(),
            new Blog\EntryBundle\BlogEntryBundle(),
        );  

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new …
Run Code Online (Sandbox Code Playgroud)

smarty symfony smarty3

2
推荐指数
1
解决办法
4328
查看次数

删除Smarty中的额外HTML空间

我们大量使用Smarty进行所有前端模板操作.我观察到以下情况:

当我的Smarty模板类似于以下内容时:

<li>
    {if $a == 'A'}
        {$var1}
    {else}
        {$var2}
    {/if}
    <br><span>SUBTEXT</span>
</li>
Run Code Online (Sandbox Code Playgroud)

传递给浏览器的最终HTML是:

<li>
                            65
                        <br><span>SUBTEXT</span>
        </li>
Run Code Online (Sandbox Code Playgroud)

我希望它更干净,类似于:

<li>
    65<br><span>SUBTEXT</span>
</li>
Run Code Online (Sandbox Code Playgroud)

或更好:

<li>65<br><span>SUBTEXT</span></li>
Run Code Online (Sandbox Code Playgroud)

无论如何,我可以使用Smarty 3中的一些配置设置吗?格式化和清理最终HTML创建的任何设置?

谢谢

smarty smarty3

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

如何将PHP smarty模板与Vue.js集成?

我在PHP中使用Smarty模板引擎,并希望将VUE.js集成到我的应用程序中,但似乎Smarty不理解Vue.js语法(双花括号)

代码如下:

home.tpl

{include file="partials/header.tpl" title="Home"} 
<body data-spy="scroll" data-target=".navbar">
    <div class="se-pre-con"></div>

    {include file="partials/navbar.tpl"}   

    <div class="container container-body">
        <div class="row">
            <div class="col-md-12" id="app">
                <h2>Test Heading</h2>
                 {{ message }}
            </div>
        </div>
    </div>
{include file="partials/footer.tpl"}
Run Code Online (Sandbox Code Playgroud)

footer.tpl

<script src="https://unpkg.com/vue"></script>
<script src="resource/js/app.js"></script>
Run Code Online (Sandbox Code Playgroud)

app.js

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  }
})
Run Code Online (Sandbox Code Playgroud)

错误信息:

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:\resource\html\templates\home.tpl" on line 11 "{{ message }}" - Unexpected "{ " <-- thrown in vendor\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php on line 11 …
Run Code Online (Sandbox Code Playgroud)

javascript php smarty3 vue.js

2
推荐指数
1
解决办法
2723
查看次数

标签 统计

smarty3 ×10

php ×8

smarty ×8

css ×1

html ×1

javascript ×1

shopware ×1

string ×1

symfony ×1

vue.js ×1