Closed (fixed)
Project:
Smarty theme engine
Version:
master
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Nov 2006 at 22:51 UTC
Updated:
2 Jan 2014 at 19:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
TeddyX commentedHere is a patch to upgrade smarty.engine 4.7 to 5.0. It is based on differences between phptemplates 4.7 and 5.0. It works for me, but I haven't much time to thoroughly test it.
Comment #2
djnz commentedRather than patch the existing code, I have used a different approach. For future maintability it is much better to use the PHPtemplate code to set variables etc. - all the smarty template engine needs to do is the smarty-specific stuff (assigning variables, fetching templates etc.)
So here is a replacement for smarty.engine that works with Drupal 5. Note that this should NOT go in themes/engines/smarty, the correct Drupal 5 place is sites/all/themes/engines/smarty. You will have to move the smarty directory over too of course (and templates_c etc.)
This is not really production ready for new installs, but if you are trying to upgrade an exisiting installation of a smarty theme to Drupal 5, give it a go!
Note that the attachment is a complete php file, not a patch (remove the .txt extension of course).
Comment #3
barretr commentedComment #4
djnz commentedYou don't need to do that barretr. Just put what you need in template.php (not smartytemplate.php) which is automatically included by the phptemplate_init() function.
Comment #5
barretr commentedComment #6
yojoe commentedI like the approach of djnz very much. I ported the Garland theme to Smarty yesterday, it works very well.
I did a few changes to djnz version of smarty.engine, I would like to present and discuss with you:
require_once drupal_get_path('theme_engine', 'phptemplate') . '/phptemplate.engine';instead of the hardcoded pathrequire_once './themes/engines/phptemplate/phptemplate.engine';$smarty_path = dirname(__FILE__).'/Smarty/libs/Smarty.class.php';to
$smarty_path = drupal_get_path('theme_engine', 'smarty') . '/libs/Smarty.class.php';This way we use the drupal_get_path() function. And, like it's written in the README of smarty.module, it's sufficient to copy just the libs directory of the Smarty download to the smarty module directory, so we look for the libs in /sites/all/themes/engines/smarty/libs and not /sites/all/themes/engines/smarty/Smarty/libs.
return _phptemplate_default($hook, $variables, $suggestions = array(), $extension);>to
return _phptemplate_default($hook, $variables, $suggestions, $extension);>$variables['user'] = $GLOBALS['user'];line in the _smarty_default() function? I mean, why do we need it when using Smarty as engine, but not when using PHPTemplate?If a node (node_1) is to be rendered, the node object is first created and then passed to the Smarty object within the $variables array (_smarty_render($file, $variables)). This is usually fine. Your template, let's call it node-typeA.tpl, can access the node_1 object and finishes without problems. But now imagine that node-typeA.tpl want's to include the teaser of another node (node_2) first. What happens? Yes, while theming the teaser of that node_2, we overwrite the variables array of the (singleton) Smarty object. The result is, that after the teaser of node_2 is themed and the control flow comes back to node-typeA.tpl, we can't access the node_1 object anymore, it has been overwritten.
That's why I commented out the static declaration of the Smarty object instance in &smarty_get_object(). This way a new Smarty object is created with each _smarty_render() call. Well, if you agree, that we can't use the Singleton pattern here, we should remove the ampersand from the function name => smarty_get_object().
Comment #7
lvthunder commentedI'm getting errors in the smarty themes. I've tried 3 of them and they all say roughly the same thing.
Here's the message.
Smarty error: [in themes/greypop_smarty/page.tpl line 10]: syntax error: unrecognized tag 'theme' (Smarty_Compiler.class.php, line 580) in C:\Users\Stephen\workspace\drupal\themes\engines\smarty\libs\Smarty.class.php on line 1095.
Also instead of primary links I get the word array. Can someone help me.
Comment #8
yojoe commentedAs I said in my post, I moved the two functions smarty_function_theme() and smarty_function_theme_links() into separate files in the plugins dir. I didn't included those two files in my post. I can upload them here too, if you want. Or you copy & paste them from the last lines of the file in post #2 and name the files function.theme.php and function.theme_links.php and put them in the plugins directory (sites/all/themes/engines/smarty/plugins).
Comment #9
robin monks commentedI've tried this patch, and still get array in the menu bar even with the function.theme.php and function.theme_links.php in the engines/smarty/plugins directory. Ideas?
Robin
Comment #10
robin monks commentedFound the answer, seems Drupal 5 handles primary/secondary links a bit differently:
Seems to work just fine.
Robin
Comment #11
robin monks commented+1 Tested & Works on Drupal 5.1, at the very least this is enough to start a 5.x branch
Robin
Comment #12
djnz commentedI am delighted that there is real interest in making Smarty work for Drupal in the best way possible. I am disappointed though that the maintainer/developers of this project do not seem to be so interested - either in a version for Drupal 5 or other improvements.
This has happened before with Drupal and Smarty, and so I set up the wgSmarty project to get things going. Then the 'official' Drupal Smarty project caught up and wgSmarty was redundant...
Now it looks like it is time to get wgSmarty going again.
Comment #13
tclineks commentedI initially like the simplified approach -- I'd have to look into if this would affect custom function registration but offhand it should be workable.
I think the best plan is to
a. get a 5-supported version out the door asap
b. and then release an updated version that allows more control in the form of custom function registration (I have this code worked out but never got it committed, I'd be happy to share).
Frankly I don't use Drupal or Smarty in my projects anymore and am open to passing the maintenance torch to someone willing.
If interested send me a message and we can work out what's best.
Comment #14
tclineks commenteddjnz and I are in communication and should have a 5.0 version out shortly!
Comment #15
djnz commentedHEAD now contains a merge of my code posted below, some 'production ready' improvements I had done, those of yojoe's comments I was able to incorporate (more documentation on those coming), and some of the helper function pre-registration code that tclineks had done for 4.7.
Amazingly, most of this seems to work (the plugin function pre-registration being the bit that needs more effort to bring my code and Travis's together) so it is nearly ready for tagging a 5.x.1.x release - testing gratefully received.
Comment #16
lvthunder commentedI'm having a problem with the primary links and the title link. It's a little strange.
OK I'm at my homepage http://photo.lvthunder.com and all the links for the title and primary links work.
If I go to say http://photo.lvthunder.com/view/photo101 and the title link is http://photo.lvthunder.com/view/photo101 and the same primary link is http://photo.lvthunder.com/view/view/photo101
Here is the source of the HTML
And here is a portion of my page.tpl is
Does anyone have any suggestions?
Also when do you think we will have a released or at least a dev snapshot of this theme engine.
Comment #17
yojoe commentedI created a new project for the port of the Garland theme to the smarty theme engine: http://drupal.org/project/garland-smarty
Anybody who wants CVS access and help maintaining this port please let me know!
@djnz: Now that the changes are in HEAD, could you please setup a drupal 5.x development release of the smarty engine?
Comment #18
Atlanticom commentedI am very interested in getting this patch up and finished. At the moment there seems to be a lack of progress, and so i would like to offer my support. I've got 8 years experience in PHP and website programming; i would only be interested in getting the SMARTY template engine working with Drupal 5 however.
Comment #19
GeekElectro commentedThe X-Cart shopping cart utilizes smarty tags. I would think quite a few X-Cart users would be interested in more easily integrating the themes between X-Cart and Drupal by using smarty tags.
Comment #20
djnz commentedIf X-Cart uses smarty as its theme engine, I would have thought it is quite easy to adapt an X-Cart theme for use with the Drupal Smarty Theme Engine, but as X-Cart is paid-for software (and presumably its themes are paid-for too) I don't think you will find any of the Open Source developers that do all the work on Drupal to be very interested in this.
This feature request should have been closed on the release of Smarty 5.x-0.1, (I am about to release a v6) so I am marking it fixed now.
Comment #21
djnz commentedFixed? I should have set it to closed.
Status -> closed.