tags:

views:

139

answers:

1

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?

+1  A: 

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.

Borealid
I thought as much, I've been looking through the Smarty code all morning. Yes I know it goes against the contemplating model as such, but I have a few options to investigate to optimise our AJAX performance and this was one of them, just trying to figure out the best method of solving my problem. Many thanks :-)
ILMV