Page 2 of 3

Posted: Thu May 24, 2007 2:27 pm
by Jenk
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.
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.

Posted: Thu May 24, 2007 4:39 pm
by Ollie Saunders
Jenk wrote:Not entirely true. A frame work with a decent model for markup generation is prefered by many over templates.
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 one :( 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.
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.
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.

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.
Maugrim wrote:[referring to ZF]...and it's excellent Internationalisation support via Zend_Locale
What's excellent about it? Is there UTF-8 support yet?

Posted: Thu May 24, 2007 6:31 pm
by Jenk
ole wrote:
Jenk wrote:Not entirely true. A frame work with a decent model for markup generation is prefered by many over templates.
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 one :( 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.
It just makes so much sense. Here is a page component (a list of items in a shopping cart) rendered in Smalltalk/Seaside..

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]]]]]]
Now when I render I can specify to Seaside which DOCTYPE I want, and it will render valid markup. Compared to needing several templates to satisfy the various DTD's, and not only needing multiple templates, I need to be able to remember those markups. Not here, I just need to deal with the application logic.

Posted: Thu May 24, 2007 6:46 pm
by Luke
hmm... that is quite neat.

Posted: Fri May 25, 2007 3:32 am
by Maugrim_The_Reaper
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?
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.

P.S. No flaming here ;).
Jenk 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.
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 ;).
What's excellent about it? Is there UTF-8 support yet?
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.

ZF is hardly the exception - any really good framework should offer excellent i18n/l10n support. It stopped being optional a long time ago.

Posted: Fri May 25, 2007 4:12 am
by Jenk
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 ;).
Knowing != Having the time, effort, or inclination to bother.

It's things like this that are holding the progression of tools like PHP back ;)

Posted: Fri May 25, 2007 5:42 am
by s.dot
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.

Posted: Fri May 25, 2007 7:40 am
by Maugrim_The_Reaper
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.

Posted: Fri May 25, 2007 9:21 am
by Jenk
I didn't say a single thing about mixing it with your domain model, but thanks for twisting my words none the less.

When you create XML feeds, do you use templates or something like the DomDocument model? Why treat (X)HTML [sic] any different?

Posted: Fri May 25, 2007 9:35 am
by s.dot
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 }?

Posted: Fri May 25, 2007 9:41 am
by pickle
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".

Posted: Fri May 25, 2007 9:53 am
by Jenk
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 }?
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.

Posted: Fri May 25, 2007 10:00 am
by Maugrim_The_Reaper
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.
Eh?
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 }?
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.

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>
If your translation object returns a translated string with placeholders (assume sprintf style) then it works fine. An Irish translation can then use the placeholder:
%s is ainm dom!
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 ;). At least one of the XML standard allows for HTML structural markup inside translations (e.g. use of <strong> which is not just for eye candy).

Posted: Fri May 25, 2007 10:59 am
by RobertGonzalez
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".
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.

Posted: Fri May 25, 2007 2:24 pm
by s.dot
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.