Skip to content
Advertisement

Tag: templates

How to escape Twig like variables on JS

I need to escape some JS twig-like variables in a twig template, but I couldn’t find anything about how to do that. This variables are used in a js templating plugin that uses the same pattern as twig for variables which is causing the twig rendering to fail Unexpected token “punctuation” of value “:” (“end of print statement” expected) in

How to create a link to another PHP page

I just converted some of my HTML pages to PHP pages, and I’m not that familiar with PHP. In my HTML pages, assuming it’s just a static web app, I can link to another page quite simply by playing the following anchor on the page: <a href=”go-to-this-page.html”>This is a link</a> So, after converting the pages to PHP in order to

Undefined variables in PHP template

I use PHP as a template language in my view layer, Is it possible to make the following a little cleaner and more concise? Unfortunately, we can not even define a function for that: Answer Using @ operator is the shortest alternative. Since PHP 7 you can also use the ?? operator. Which does exactly what the @ operator does,

Smarty: unset an array index in template

I would like to do {unset($array[‘index’])} into a Smarty 3 template. Is such a syntax (or similar) supported ? After Googling and doc reading I can’t find something satisfying. Maybe I should ask for a feature request to Smarty dev team ? 🙂 Anyway, how would you do this given the currently available template functions ? Answer I don’t think

vsprintf or sprintf with named arguments, or simple template parsing in PHP

I’m searching for a way to use named arguments for sprintf or printf. Example: or via vsprintf and an associative array. I have found some coding examples here http://php.net/manual/de/function.sprintf.php and here http://php.net/manual/de/function.vsprintf.php where people wrote their own solutions. But my question is, is there maybe an standard PHP solution out there to achieve this or is there another way, maybe

Advertisement