D
D
Denis Goncharenko2017-04-07 10:29:55
Yii
Denis Goncharenko, 2017-04-07 10:29:55

What to choose as a template engine?

The site has some type of content that users create. This content has an html template, which is also edited by users. We need to make sure that users have the opportunity to use certain variables in these templates and call certain functions. That is, of course, it is impossible to give access to php code to users, so you need to use some kind of template engine. If there were only variables, it would be possible to write your own solution that would change something like {{var}} to variables during rendering with a simple regular expression, but you also need functions, essentially the same variables but with passing parameters. I wanted to implement it similarly to variables, but I ran into difficulties when compiling regular expressions, because there, the difficulties of formatting parameters begin (quotes for strings, the absence of unescaped quotes inside a parameter, etc. ) In short, I decided that it is more reliable to use something ready-made. There is experience with TWIG, and, in fact, it is the first one that comes to everyone's mind. but if you use it, then you need to somehow disable all the rest of its functionality, can this be done? Those. leave only the variables and functions that will be used from any one specified class. Those. disable logical constructs, loops, built-in functions of twig.
The final question is: Is it possible to disable everything that is not needed in twig, if so, how? And if not, what can be used instead?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Esin, 2017-04-07
@denis79513

Twig has a sandbox.
https://twig.sensiolabs.org/doc/2.x/api.html#sandb...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question