1

I have this hidden field :

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

And this input text

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

I want do a test on the value of the PartNumber value="{{ price.getPartNumber }}"

If it contains this String 35-l0l-1003 I should change the value of the value="{{ price.getLt }}" to 30

I should use strpbrk to search a string for any of a set of characters. I'm beginner in Twig and I don't know how can I add it. Please can you help me. Thank you.

vero
  • 1,005
  • 6
  • 16
  • 29
  • Possible duplicate of [Find substring in the string in TWIG](https://stackoverflow.com/questions/13007288/find-substring-in-the-string-in-twig) – Shira Jun 21 '17 at 07:58

1 Answers1

1

In your case just use :

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

However you can add almost every function in Twig. Here is a simple implementation of the file_exist function (I'm actually doing it in my Controller core class)

    //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);
drumz
  • 65
  • 7