Forum
can i call custom php function in template (html)?
I have a function that formats a string in different way. I am calling that function in php files using below code
echo CustomFormatString('This is my string')
But I want to call this function from template (.html) files too, some thing like below:
<perch:custom function="CustomFormatString"><perch:content id="style_long_desc" /></perch:custom>
The function is written as an addon, and works on php pages (layout/.php and pages/.php)
do you think something like this is possible
Yes, you could do that with a custom template handler - you can see examples in both Members and Shop.
A simpler way might be to format it before the template in an
each
callback.You might be able to do it by simply using template layouts:
In your template:
Then, create a file:
perch/templates/layouts/my.function.php
containing:To show that it can be done with editor input:
this worked great guys...
thank you Simon so much for the example code. I could not have figured out without it :-)