Are there template engines that can be used both on the backend (PHP) and frontend (JS) side? In particular, I am interested in a solution that allows the use of a single syntax in a template and implements three main operations:
- Variable insertion
- Condition
- Cycle
The application is to implement widgets that can be rendered on the backend:
<ul> <?php foreach($todos as $todo): ?> <!-- Дублирующийся шаблон --> <li><?= $todo->content ?></li> <?php endforeach; ?> <li> <input type="button" value="add"/> </li> </ul> with the addition of logic at the frontend level and subsequent state change by applying the same templates:
function TodoListView(ul){ var $ul = $(ul), // Дублирующийся шаблон liTemplate = tempalte('<li>{todo.content}</li>'); $ul.find('input:button').on('click', function(){ $ul.prepend(liTemplate({ content: 'FooBar' })); }); }