Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call smarty plugin function directly from PHP

Tags:

php

smarty

So I can use the Smarty plugin html_options within a template like this:

{html_options options=$arr }

But what I want to do is call the function behind this plugin (smarty_function_html_options) directly from PHP.

I'm sure this must be possible, has anyone got any ideas on how to achieve this?

like image 885
Ben Everard Avatar asked Jul 23 '26 06:07

Ben Everard


1 Answers

First, find the PHP file containing html_options in the Smarty install. Then, include this function from your code. Finally, call the appropriate method in your PHP code.

There's no "official" Smarty way to do this, at least, none that I know of. I just double-checked the documentation and didn't see anything. But since Smarty is itself really just a program written in pure PHP, you shouldn't have problems with the above.

Note that if you have to do this, your code is "wrong" in conformance to the templating-system model: the idea of a templating system is to separate presentation from data. This means that if you have intense code which needs to generate raw HTML, you're doing it wrong.

like image 93
Borealid Avatar answered Jul 24 '26 22:07

Borealid