Can I use php code in an xtemplate theme? If so, how? I'd hate to have to start over with phptemplate...

Comments

TDobes’s picture

Well, it depends.

What do you need it for?

If you need to override a theme function (or functions), you can do so by creating a .theme file in the same folder as the xtemplate.xtmpl, then placing code in it to still use your xtemplate for the functions it works with (_node, _command, _page, and _block)

You could place the following code at the top of your .theme file to accomplish this:

include_once('themes/engines/xtemplate/xtemplate.engine');
$theme_engine = 'xtemplate';
if (function_exists($theme_engine .'_init')) {
  call_user_func($theme_engine .'_init', $themes[$theme]);
}

When attempting to theme an item, Drupal will use the following precedence:
1st - look for function in the theme file
2nd - use template (if applicable)
3rd - use the default (non-themed) function

gordon’s picture

I did a little work on phptemplate a while back, as there were some missing vars, but now you can convert your xtemplate theme to phptemplate very quickly. I was going to write a small howto but I haven't gotten around to it.

I converted a fairly complex one the other day, and it only took me a couple of hours.

If you would like me too, send me your xtemplate theme, and I will convert it to phptemplate for you. and I will make some notes and create a howto.

Just send it to gordon@heydon.com.au
--
Gordon Heydon
Heydon Consulting

--
Gordon Heydon

gordon’s picture

Hello,

I have written a quick howto so you can convert you them yourself.

http://www.heydon.com.au/?q=node/636

If you find any problems please tell me, and I will fix them.
--
Gordon Heydon
Heydon Consulting

--
Gordon Heydon