How to retrieve all Variables from a Twig Template?

前端 未结 14 1511
抹茶落季
抹茶落季 2020-12-08 00:24

Is it possible to retrieve all variables inside a Twig template with PHP?

Example someTemplate.twig.php:

Hello {{ name }}, 
your new email is {{ ema         


        
14条回答
  •  心在旅途
    2020-12-08 01:05

    This Question has a douplicate – there I found a useful and kind of more powerfull RegEX than above. This one, I've improved to match more precise:

    \{\{(?!%)\s* # Starts with {{ not followed by % followed by 0 or more spaces
      ((?:(?!\.)[^\s])*?) # Match anything without a point or space in it
      (\|(?:(?!\.)[^\s])*)? # Match filter within variable
    \s*(?

提交回复
热议问题