Not entirely true. A frame work with a decent model for markup generation is prefered by many over templates. A lot of (Smalltalk)Seaside developers consider Templating a thing of the 90's. True for some Ruby/Rails developers too.Maugrim_The_Reaper wrote:A framework without templating is a framework about to die a swift painful death. It practically rules the entire V in MVC.
a few questions
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
That's very interesting. My framework is slightly oriented to the Entity Renderer Pattern (exactly what the pattern is, is something I would really love to blog about but I don't have oneJenk wrote:Not entirely true. A frame work with a decent model for markup generation is prefered by many over templates.
Yes. To my mind this makes ZF better than all the other frameworks out there. A lot of them are way to ambitious and force you down a certain path. Although I have to admit PRADO intrigues me greatly yet I've never downloaded it.Ninja wrote:not if the framework is flexible. some frameworks try and strong-arm you into using only their components, but that's why you don't use those frameworks unless you like that. Zend framework's components are pretty interchangeable.
As a learning exercise writing your own framework is a great idea. As is any largish scale code project, it doesn't have to be a framework. I tried to write a forms library and learnt a massive amount doing that. I can't emphasize how important reading up on design patterns, refactoring and unit testing is though.
Now I'm writing my own framework, as I go, not to learn, although I definitely am, but because none of the other framework satisfy me on a fundamental level.
What's excellent about it? Is there UTF-8 support yet?Maugrim wrote:[referring to ZF]...and it's excellent Internationalisation support via Zend_Locale
It just makes so much sense. Here is a page component (a list of items in a shopping cart) rendered in Smalltalk/Seaside..ole wrote:That's very interesting. My framework is slightly oriented to the Entity Renderer Pattern (exactly what the pattern is, is something I would really love to blog about but I don't have oneJenk wrote:Not entirely true. A frame work with a decent model for markup generation is prefered by many over templates.Maybe I should hit patternsforphp.com) and very oriented towards TDD. View helpers are good but sometimes you need a proper object with proper interface to be responsible for a complex piece of HTML generation.
Code: Select all
renderCartOn: html
html div class: 'content'; with: [
html unorderedList class: 'items'; with: [
self items do: [ :item |
html listItem with: [
html anchor callback: [:x | self selectItem: x]; text: [html text: item name]]]]]]- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Sometimes. It depends on whether the framework implements MVC, or implements MVC and decent OO. In the Zend Framework the only interface being enforced is Zend_View_Interface. If you write a Facade to Smarty implementing that Interface then it should work perfectly well. In practice this does have some unforeseen problems - though these are being fixed and I long ago resisted the urge to allow ZF Controllers do any automatic View handling. There are a few good blog posts out there on integrating Smarty into the ZF. It's a pretty simple exercise.scottayy wrote:Then, later on, I decide to try out a php framework. Will I be forced to use their "view" instead of the one I have already learned?
P.S. No flaming here
I'd wager a framework without template support wouldn't last long. How many PHP Developers honestly know even the basics of markup generation? Many != MostJenk wrote:Not entirely true. A frame work with a decent model for markup generation is prefered by many over templates. A lot of (Smalltalk)Seaside developers consider Templating a thing of the 90's. True for some Ruby/Rails developers too.
Unicode support isn't the fault of a framework - the PHP developers were too short sighted and everyone now sits in Unicode Hell until PHP6. But a lot of i18n stuff is not about encoding (where mainly string manipulation by PHP causes headaches). There's handling of dates, translations, localisation data, date calculations, currency formatting, etc. The ZF has an impressive array of tools which aren't themselves above being subclassed if needed.What's excellent about it? Is there UTF-8 support yet?
ZF is hardly the exception - any really good framework should offer excellent i18n/l10n support. It stopped being optional a long time ago.
Knowing != Having the time, effort, or inclination to bother.Maugrim_The_Reaper wrote:I'd wager a framework without template support wouldn't last long. How many PHP Developers honestly know even the basics of markup generation? Many != Most.
It's things like this that are holding the progression of tools like PHP back
Even if I decide to not use a framework for a while, and just stick to learning templating for now, it's a step in the right direction, right?
What you guys are talking is far above my head at the moment, but I want to be ensured that I'm not wasting my time.
What you guys are talking is far above my head at the moment, but I want to be ensured that I'm not wasting my time.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
No, it's not a waste of time. Tons of applications use Smarty everyday. Tons more use an alternative library, or XSLT, or Jenk's precious markup generation
.
Presentation Logic needs to be kept separate - even outside MVC it's important. Template Engines (or alternatives) serve as an obvious means for doing so. I suppose one last thing to remember is that even Templates are capable of being refactored - if you duplicating presentation (like various menus using almost the same markup and logic) then extracting those into a common function (say a View Helper or a Smarty Plugin/tag) makes life easier maintaining templates.
Presentation Logic needs to be kept separate - even outside MVC it's important. Template Engines (or alternatives) serve as an obvious means for doing so. I suppose one last thing to remember is that even Templates are capable of being refactored - if you duplicating presentation (like various menus using almost the same markup and logic) then extracting those into a common function (say a View Helper or a Smarty Plugin/tag) makes life easier maintaining templates.
Is it considered OK to add links and text to the templates? Or should I write the text and links into arrays and assign them to the template, then loop over them with { foreach }?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I'm relatively new at templating so I might not know the correct way to do this, but I put absolutely everything I can in templates. Obviously if I have to dynamically generate navigation or some other text, I assign that when necessary. Generally though, I try to stick to the concept of "If the user sees it, it's in a template".
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
If they are static (and will always be there for that template) then I don't see why not. Things like header/banner text with a link to the homepage and so forth.scottayy wrote:Is it considered OK to add links and text to the templates? Or should I write the text and links into arrays and assign them to the template, then loop over them with { foreach }?
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Eh?Jenk wrote:I didn't say a single thing about mixing it with your domain model, but thanks for twisting my words none the less.
I have no problems with text and links. The main issue of sorts with templates and text is when translations are required. Something like Zend_Translate (pick any other i18n framework even) can be inserted into the template to dynamically translate text. Smarty doesn't have this by default so you can do it externally and use simple {$var} placeholders, or create a custom Smarty tag which proxies to a Translate object.scottayy wrote:Is it considered OK to add links and text to the templates? Or should I write the text and links into arrays and assign them to the template, then loop over them with { foreach }?
A ZF template might look like:
Code: Select all
// Controller logic...
//$t = new Zend_Translate('gettext', '/path/to/gettext/file.mo');
//$view->t = $t;
//$this->view->render('template.phtml');
<html>
<head>
<title>Scottayy's Super Site</title>
</head>
<body>
<p><?php printf($t->_("Hey folks, my name is %s!"), 'Scottayy'); ?></p>
</body>
</html>All you'd need then is some translation file to contain translated strings, with the English default (as in your template) acting as keys. Gettext is a machine format, there's also TMX and XLIFF (XML standards), database driven options, and of course the ever popular PHP array%s is ainm dom!
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I typically put nothing into the templates but the markup and the template vars for parsing. All the content, text and other stuff will either be page specific or config specific, and in both cases, it comes from the database.pickle wrote:I'm relatively new at templating so I might not know the correct way to do this, but I put absolutely everything I can in templates. Obviously if I have to dynamically generate navigation or some other text, I assign that when necessary. Generally though, I try to stick to the concept of "If the user sees it, it's in a template".
So, at first, it feels like I'm doing double the work (with creating a .php page and a .tpl page for each new page). But I'm sure it will come in handy when I decide to change the layout or sell a web site.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.