How to reference Smarty variables inside {php} tags

I gotta’ be honest, I’ve never used the Smarty Template Engine before in my life. I’m currently working on a project to integrate WordPress and JobberBase so they use the same WordPress theme. JobberBase uses Smarty, so I’m getting a crash course.

You can use PHP in the template (.tpl) files and reference the values of the assigned Smarty template variables like this:

{php}
  $html_title = $this->_tpl_vars['html_title'];
  $echo $html_title;
{/php}

I’m sure Smarty users cringe at this sort of thing, being that it adds business logic to the template files. But, this is just the functionality I need to hack the JobberBase templates without mucking around in core JobberBase code.

I found this solution in the Smarty FAQ after hours of Googling.

This entry was posted in Web & Software Development and tagged , , , . Bookmark the permalink.

2 Responses to How to reference Smarty variables inside {php} tags

  1. Giancarlo says:

    Thank you very much for the article as this was exactly the reference I was looking for!

  2. Elli says:

    Thanks I needed this. Just because something is written in PHP doesn’t mean it’s business logic, template files can also be written in php 😉 Personally I think smarty is a piece of crap and I would rather use PHP templates, but in my current situation I have to work with it.

Leave a Reply

Your email address will not be published. Required fields are marked *