【问题标题】:Find characters in string in TWIG在 TWIG 中查找字符串中的字符
【发布时间】:2017-11-23 23:44:03
【问题描述】:

我有这个隐藏字段:

<input type="hidden" id="PartNum" name="pn" value="{{ price.getPartNumber }}">

还有这个input text

<input type="hidden" id="ltid" name="lt" value="{{ price.getLt }}">

我想测试PartNumbervalue="{{ price.getPartNumber }}"的值

如果它包含这个字符串35-l0l-1003 我应该将value="{{ price.getLt }}" 的值更改为30

我应该使用strpbrk 在字符串中搜索任何一组字符。 我是Twig 的初学者,我不知道如何添加它。 请你帮帮我。 谢谢。

【问题讨论】:

标签: php html twig


【解决方案1】:

在你的情况下,只需使用:

 {{'Toto' in 'Tototatattiti'}} //Will return true
 {{'Toto' in 'Tata' }} //Will return false

但是,您几乎可以在 Twig 中添加所有功能。这是file_exist函数的简单实现(我实际上是在我的Controller核心类中实现的)

    //Getting twig by a loader
    $twig = $this->templating;
    //Getting twig environnement
    $env = $twig->getTwig();
    //Adding the new function
    $fe = new Twig_SimpleFunction('file_exists', 'file_exists');
    $env->addFunction($fe);

【讨论】:

    猜你喜欢
    • 2012-10-12
    • 2011-01-11
    • 2011-07-13
    • 2014-03-26
    • 2016-01-26
    • 2014-02-04
    相关资源
    最近更新 更多