Smarty coming soon? (24 posts)

  1. ChrisBoulton
    Posted 12 years ago #

    I have read the numerous posts around the place, and have also looked in the 'future' section of the site. I noticed there is discussion of including the smarty based template system into WordPress..
    This will probably be the deciding factor for me, if I should move to WordPress or not from bBlog.
    I love the flexibility that bBlog has through its smarty-centric code, where you have functions such as {getrecentposts} as well as modifiers for your posts, such as textile, bbcode etc which can all be changed about easily in the templates.
    I'm not a huge fan of the current 'template system' in WP, if it can actually be called that. The plugins architecture, from what i have looked at is also something that lacks a bit (don't get me wrong, its great, but i'm just inlove with the way bBlog and smarty handle things).
    For an example of what i am talking about, take a look at the following templates that I use on my site (powered by bBlog) (please ignore my sloppy html and use of tables - this is something i plan on fixing sometime soon!)
    I do know some people aren't real fans of the smarty-centric or smarty based template system, however i see it has numerous advantages.

  2. Anonymous
    Posted 12 years ago #

    From the code you've shown us, it looks to me like a modified version of PHP. Why do this when you have direct access to PHP in the form of plugins and even modifying the core files yourself (though that isn't recommended)?
    Smarty tags may be fine for small code, but when you have an interpreter interpreting code and that code interpreting it's own seperate code, well, you run into speed issues.
    This just seems like a big waste of time to me.

  3. ChrisBoulton
    Posted 12 years ago #

    Well, it could be alot simpler and done directly in PHP, I just did it this way to save some time for myself, instead of stuffing about finding out exactly where in bBlog things happen (which is a lengthy process). I know in WordPress the code is a lot cleaner and easier to follow though.
    I find that using smarty is a quicker alternative to actually editing the core and the code. It allows the flexibility. I could have done the complicated things i chose to do in the PHP files, but i just chose to make my own templates a mess.
    But these are just my opinions on the template system and design.

  4. ringmaster
    Posted 12 years ago #

    Actually, Smarty builds php files from the templates and stores them in cache until the original template is changed. When the page is displayed the second time, it's executing PHP code.
    Nonetheless, I agree that it seems less flexible to use the Smarty templates than native PHP.

  5. ChrisBoulton
    Posted 12 years ago #

    Going by what I am about to say now, I am probably about to completely contradict what I have previously said about smarty..
    Using native PHP for templates cannot really be called a template system. Isnt the idea to remove the php related things and just provide straight HTML logic in the templates? (Yep, I have contradicted myself).. I know that you cant really call smarty a template system either if we go like that due to the advanced nature's it supports such as {if} and {foreach}.
    Being a developer of forum software, the template system is something that I am always looking at. I have currently opted to stay with the basic template system design of just HTML in the templates, and calling extra templates in the PHP then assigning them to a variable when needed.

  6. davidchait
    Posted 12 years ago #

    Sorry, but index.php IS the template. It is just a default. To call it any more than that is misrepresenting the system.
    Now, you CAN do huge changes to the look and feel of your blog without touching index.php, just modifying wp-layout.css. But, EEEK, wp-layout.css might change with updates too! Which means it is really just a default as well..
    I like having a minimal set of places I change things. Since there are logic functions (if-then, loop, test) I want integral to my template, I wouldn't want to base them out in some other file. That doesn't make things easier, just spreads out content creation that much more. Well, just IMHO! :)

  7. stephenv
    Posted 12 years ago #

    index.php never changes... I've had the same one through all the betas and probably could have safely used the one from 1.02
    There are 3 files I never touch when I update or patch: index.php wp-layout.css (although I renamed it) and wp-comments.php
    I do have to keep editing wp-functions/links.php to clean up the ul/li the way I like it though.

  8. unteins
    Posted 12 years ago #

    index.php DID change from one of the 1.0.x releases to 1.2 because I posted on here about it (http://wordpress.org/support/3/5969
    It may have been a bug in the older version, but when I tried to keep index.php from my old version I got the bad wrong behavior.

  9. unteins
    Posted 12 years ago #

    Out of curiosity, what is the class-smarty.php for?
    And yes, if there won't be smarty templates please more API hooks. Especially in the backend so that plugins can tie in with the administrative functions as well.

  10. patmfitz
    Posted 12 years ago #

    Having been through the PHP vs. template systems argument again and again, I came to the conclusion that PHP is best; however, if I was designing software like WordPress I would use a template system like smarty.
    Because if you want to have plug-and-play, shareable templates, then using PHP is a massive security vulnerability. An attacker can post a whiz-bang set of template files that also contain malicious code.
    In a template system, you are limited in what the template files can do, so you can install 3rd-party template files without worry.

  11. patmfitz
    Posted 12 years ago #

    Furthermore, what if WordPress moves to a multiple-blog setup like MoveableType, and you want each user to be able to customize his own template? Surely you don't want all those users having access to PHP where they can wreak havok.

  12. ChrisBoulton
    Posted 12 years ago #

    The point that patmitz point out there, about plug-and-play templates is a very good one. I would have to agree about the multiple-blog setup idea too.
    I am disappointed that we wont be seeing smarty anytime soon in WordPress, or even another template system (even a basic one).
    If i give my little brother a smarty template he can pretty much understand all of it, even some of the logic. I let him look at WordPress' index.php and he was confused..

  13. cubal
    Posted 12 years ago #

    I'm really keen on smarty. I'm a reasonably experienced php programmer, but smarty has a number of (really good) benefits:

    • Multiple templates easy - just put the directory in your templates/ dir, and change a select box in the admin section. Good for a change, or as mentioned above, for multiple users.
    • Separation of presentation from content from code. Smarty is purely presentation, and lets you just worry about the design, without even having to worry about what the code is doing.

    In addition, there isn't that much extra overhead, and it takes about 5 minutes to learn. This is the one feature that may keep me on bBlog - it's a tough decision.

  14. NuclearMoose
    Posted 12 years ago #

    @Chris Bouton--
    "I am disappointed that we wont be seeing smarty anytime soon in WordPress, or even another template system (even a basic one)."
    While it's been stated many, many times that Smarty is not the right fit for WordPress, who has said that we won't be seeing any kind of a template system?
    Also, a general comment to all -- this is not MT. It should not be "like" MT. No single piece of software will ever please all people. However, I believe 100% in the dev team. That's not to say that I always agree with them, because I don't. The thing is, if you really want MT-functionality, well, you have an option for that. I would shudder to think of WP evolving into an MT clone. Yikes!
    That being said, there is lots of room for innovation. The plugins are coming fast and furious, and they are adding a lot of great things to the WP experience.
    WordPress is still the new kid on the block, and already it's kicking ass. Just wait until you see what the future holds.

  15. ChrisBoulton
    Posted 12 years ago #

    "Also, a general comment to all -- this is not MT. It should not be "like" MT. No single piece of software will ever please all people. However, I believe 100% in the dev team. That's not to say that I always agree with them, because I don't. The thing is, if you really want MT-functionality, well, you have an option for that. I would shudder to think of WP evolving into an MT clone. Yikes!"
    I haven't really checked out MT, because of the fact that its written in perl. MT has logic in templates?
    "That being said, there is lots of room for innovation. The plugins are coming fast and furious, and they are adding a lot of great things to the WP experience."
    Thats true, and some are excellent, its just there isnt enough 'extendability' and functionality with the included hooks etc.

  16. cyclonus
    Posted 12 years ago #

    As much as I like Smarty, and personally think that WP would be adding some easy functionality by using it, I can understand developers of WP not wanting to use it and opting for something else to replicate template functionality.
    It sounds like Smarty's definitely out of the picture, so I don't understand why it's listed here: http://wordpress.org/about/future/. Should it perhaps says "templating" instead?
    Some form of easy templating should be done. I really don't think sticking things in a .php file is the best solution, since with Smarty you assign variables to the class and you pick a template and voila. So it's easy to switch stuff around, with an index.php as the template file, well ... it's not dynamic. Smarty also takes care of caching and other things. It'd be nice to see all these things handled in WP.

  17. TechGnome
    Posted 12 years ago #

    Smarty in WP, wouild be a deal breaker for me. Not to say I would stop using WP, I just wouldn't upgrade past that point. I've worked with Smarty-Enabled systems before. It was royal pain. "takes about 5 minutes to learn" my arse - I spent a year "learning" it and still had problems. It may have been the implementation of the Smarty system within that system, but it became highly inflexible and hard to trace when debugging. And it left a bad taste in my mouth from the experience.
    As for index.php not being dynamic..... I can change styles with the flip of a switch, get something completely different and not have to change any thing anywhere else.
    If others want to use smarty, more power to them, but it isn't form me. If WP ever does go smarty, I hope the developers will keep the rest of in mind an make it so that smarty is optional (or non-smarty is optional).

  18. eadz
    Posted 12 years ago #

    If you only support php templates, then people who don't already know php will have to learn it.
    And the same goes with smarty. But I think that the smarty syntax is easier to learn than the php syntax for beginners who don't know either.
    But Smarty only comes into it's own when you use it to it's full potential. that is smarty based plugins , caching and functions. Example: Putting {getlinks cat='blogs_i_red'} will get a list of links of the blogs you read and put them into your template. Also stuff like {$post.datetime|date_format:since} will output the post's date and format using the 'since' style ( 3 hours ago etc)
    It means the templates tell the program what to display, not the other way round, making the program more efficent by not doing stuff that's not shown in the templates.
    But to have something like that requires a modularized OO core . I did consider adding smarty to wordpress but I thought it would have been quicker to write a blogging app from scratch (bBlog) and that way I could take full advantage of Smarty. Just becasue I love smarty so much.

  19. Anonymous
    Posted 11 years ago #

    Interesting discussion.
    I want to use wordpress as blogsystem but as other people mention it lacks for me of a template functionality. To edit the index.php or other "display" files isn't very applicable or hacking the css.
    Furthermore it seems that class-smarty.php isn't be updated (i think some basic wordpress functions are missing) but its not bad at all, its easy to update it.
    Is anobody there who's running wordpress with smarty?
    P.S: Another good point of this discussion is to use a caching system (file and http)
    there was a discussion last two weeks about http caching headers
    if you interesting in this topic

  20. hanni
    Volunteer Moderator
    Posted 11 years ago #

    Why have 'template tags' when you've got PHP? Perhaps that's why a lot of people switched from MT and from template tags.

  21. Zarniwoop
    Posted 11 years ago #

    For the caching discussion: Have you ever tried the Statizice Reloaded plugin? Caching is done quite simple but it works.

  22. Anonymous
    Posted 11 years ago #

    Thanks for your hint about the Statizice Reloaded plugin:)
    >Why have 'template tags' when you've got PHP?
    Well this is an endless discussion. Either you like the philosophy about templates (seperate design/code) or not.
    This is the same endless discussion with guys who like OO or the tranditional "function" way. The traditional guy will ask you why to use design patterns if the problem can be solve with e.g. 20 code lines...
    My intension is not to start a "flame war". Maybe both variants (template/modifying php) can be supported in future, whereas the "traditional way" is default:)
    But my main question is, if anobody is running wordpress with smarty?:)

  23. dille
    Posted 11 years ago #

    When I started using b2 2 years ago, I wished it had a better template engine than it did. Using PHP functions, like it's still done today in WP, leads to more cluttered templates. For me, that's not an issue; I eat, sleep and breathe PHP. For someone like my girlfriend, or my dad, PHP is complex, confusing, and something they generally don't understand, something they want to stay away from.
    What irks me more about using straight PHP functions is the fact that functions tend to change as the application grows. WP is no exception to that. That means that with every upgrade, I have to cross my fingers and hope that everything still works like it used to. Also, I have to make sure that nothing I changed is overwritten by the upgrade. It shouldn't be like that, and it doesn't have to be.
    Those that say that a template engine is "just replacing < ?php the_thingy ?> with {$thingy}" don't understand the long-term benefits of a template engine. If you use {$post.title} instead of < ?php the_title(); ?>, it's not about saving those few keystrokes. Who cares about a few keystrokes? You'll only have to do that 1 or 2 times anyway.
    It's about making sure that your template doesn't have to change when the_title() does. For my girlfriend and my dad, that's great news. For me, it means that I can upgrade all I want, and unless {$the_title} is somehow no longer assigned, I can leave my templates alone.
    Even better, since I use Smarty for other pages and things, I can really integrate WP with the rest of the site; I can use one, and just one, header file and just include that everywhere. Need to change something? Changing it in one file changes it everywhere.
    I've seen people say "You can use the shorthand < ?= ?> construction". Well, yes, you can, if your server is configured to allow that; it doesn't play nice with other XML < ? ?> constructs, which (for me, being my own web hoster) is a reason to disable it. Besides, it's not about saving those few keystrokes. Another favorite seems to be "Smarty is difficult, evil, and it eats your children". I've used Smarty for several years, and although it needed some "getting used to" (coming from another template engine which did things differently), I've never found it very hard to use. I like the fact that I can place "modifiers" on vars ({$var|uppercase}, for example), and that it caches the templates to PHP files. I also hear these "Smarty is slow" remarks, but not from people who've actually used it (not just "looked at it", but really "used it").
    However, nobody should be *forced* to use Smarty, or any other template engine, if they don't want to. The best of both worlds for me would be having every function *return* it's thing instead of just echoing it, of at least have a get_... version of each function. That way, I will be able to use template engine I see fit, and the "I want plain PHP"-types can use plain PHP. Everybody wins.
    Of course, I could write a getter function that just opens an output buffer, runs the specified function with parameters, and tosses back the contents of the output buffer. Don't know what it would do to performance, though.
    Well, those were my lengthy 2 cents... =]

  24. Wim
    Posted 11 years ago #

    Indeed, I agree with dille, including (getter) functions that return would make smarty support possible and give people the choice. I like the wordpress design a lot, but to nicely integrate it in my websites I would like to use smarty like on the rest of my pages.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.