Closed OnkelTem closed 5 years ago
https://www.php.net/manual/en/function.range.php
The native PHP function works just fine. Why not using it?
ul
each val in range(1, 10)
li= val
Oh, really? Come on! Didn't know we can use native functions. But wait, isn't it unsafe?
Apart from that, is there still a way to add an extension function?
Unsafe? coding pug code is the same "safety" level as coding in PHP (or in JS for pugjs). As long as you don't render pug code that has been typed by untrusted user, there's no risk.
There are several ways to use PHP functions inside your template: first create a global function and include it before render. You also pass it as a closure as a view variable or using Phug::share
for global use. See https://phug-lang.com/#shared-variables-globals-array
Or you can share a object that handle the methods you want as methods.
I need the
range()
function which for some reason is not there already. So I'd like to create one but I couldn't found anything helping in the docs. Could you please show an example of adding a function?