Challenging an Assumption About What an Easy tpl.php Looks Like

View: New views
15 Messages — Rating Filter:   Alert me  

Challenging an Assumption About What an Easy tpl.php Looks Like

by Shai Gluskin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gang,

Every tpl.php file that I've seen in any theme is written in html with php interspersed for putting in variables. I think part of the reasoning for this approach is that it would be easier for non-geek designers to read such pages.

I want to challenge that. I think all those php open-close and all the "print" commands makes for very hard-to-read code. Tonight, as an experiment, I rewrote the node.tpl.php file from Zen from html to php. I think it is a lot easier to read. And it's sure a lot easier to comment.

I pasted my rewritten version and the original from Zen onto a pastebin:
http://pastebin.ca/1614186

Anyway, I'd be curious what other's opinions are on this.

best,

Shai

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by David Hazel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

While "easier to read" is probably a personal preference, it can be a real pain to track down extra/missing single quotes.

On Sun, Oct 11, 2009 at 7:46 PM, Shai Gluskin <shai@...> wrote:
Gang,

Every tpl.php file that I've seen in any theme is written in html with php interspersed for putting in variables. I think part of the reasoning for this approach is that it would be easier for non-geek designers to read such pages.

I want to challenge that. I think all those php open-close and all the "print" commands makes for very hard-to-read code. Tonight, as an experiment, I rewrote the node.tpl.php file from Zen from html to php. I think it is a lot easier to read. And it's sure a lot easier to comment.

I pasted my rewritten version and the original from Zen onto a pastebin:
http://pastebin.ca/1614186

Anyway, I'd be curious what other's opinions are on this.

best,

Shai

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting




--
Email is not a secure form of communication!

Drupal Consultant
http://www.hazelconsulting.com/
253.686.0296
dave@...
skype: hazelconsulting
gtalk:kananii
http://www.facebook.com/davidhazel
ICQ: 366587185

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Cameron Eagans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Agreed. I prefer the way it's usually done.
-----
Cameron Eagans
Owner, Black Storms Studios, LLC
http://www.blackstormsstudios.com


On Sun, Oct 11, 2009 at 9:02 PM, David Hazel <dave@...> wrote:
While "easier to read" is probably a personal preference, it can be a real pain to track down extra/missing single quotes.

On Sun, Oct 11, 2009 at 7:46 PM, Shai Gluskin <shai@...> wrote:
Gang,

Every tpl.php file that I've seen in any theme is written in html with php interspersed for putting in variables. I think part of the reasoning for this approach is that it would be easier for non-geek designers to read such pages.

I want to challenge that. I think all those php open-close and all the "print" commands makes for very hard-to-read code. Tonight, as an experiment, I rewrote the node.tpl.php file from Zen from html to php. I think it is a lot easier to read. And it's sure a lot easier to comment.

I pasted my rewritten version and the original from Zen onto a pastebin:
http://pastebin.ca/1614186

Anyway, I'd be curious what other's opinions are on this.

best,

Shai

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting




--
Email is not a secure form of communication!

Drupal Consultant
http://www.hazelconsulting.com/
253.686.0296
dave@...
skype: hazelconsulting
gtalk:kananii
http://www.facebook.com/davidhazel
ICQ: 366587185

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting



_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Greg Holsclaw-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I think when you factor in the perspective of whom may be making the changes, the question of ‘easier to read’ may change.

 

With the full PHP version I think it is less clear where non-geek HTML designers should make the changes, since it is all PHP code.

 

In the HTML with PHP mixed, at least it is clear that the designer should make any changes inside the <?php … ?> regions, while there fewer clear indicators where HTML updates should be make, or how to visually find them.

 

As an aside, the indenting of the HTML by DIV level is lost in the full PHP version which I think designers were feel keenly.

 

Also the difference between single and double quotes may be lost of a designer, as well as escaping characters (if needed).

 

My 2 cents of course.

 

Greg

 

From: consulting-bounces@... [mailto:consulting-bounces@...] On Behalf Of Shai Gluskin
Sent: Sunday, October 11, 2009 7:47 PM
To: A list for Drupal consultants and Drupal service/hosting providers
Subject: [consulting] Challenging an Assumption About What an Easy tpl.php Looks Like

 

Gang,

Every tpl.php file that I've seen in any theme is written in html with php interspersed for putting in variables. I think part of the reasoning for this approach is that it would be easier for non-geek designers to read such pages.

I want to challenge that. I think all those php open-close and all the "print" commands makes for very hard-to-read code. Tonight, as an experiment, I rewrote the node.tpl.php file from Zen from html to php. I think it is a lot easier to read. And it's sure a lot easier to comment.

I pasted my rewritten version and the original from Zen onto a pastebin:
http://pastebin.ca/1614186

Anyway, I'd be curious what other's opinions are on this.

best,

Shai


_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Khalid Baheyeldin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Anyway, I'd be curious what other's opinions are on this.

I find it harder to read. It may be just what I am used to after 6 years of Drupal.

I think php blocks are sometimes more readable than interspersed HTML and PHP, but this is only when you have a lot of control statements and such. A mere <?php print $foo ?> is acceptable to intersperse with HTML IMO.
--
Khalid M. Baheyeldin
2bits.com, Inc.
http://2bits.com
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Jeff Greenberg-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Hazel wrote:

> While "easier to read" is probably a personal preference, it can be a
> real pain to track down extra/missing single quotes.
>
>

Not only that, but in my experience, once the template is complete, it
will more often be the case that new HTML needs to be dropped in than
the PHP being changed, and having the HTML as strings makes that very
time consuming, where being able to just paste it or type it can be a
few minutes' work.
_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Matt Chapman-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a difference between the two as to whether the file can be
loaded and safely edited in Dreamweaver in WYSIWYG mode? (I don't use
DW, but I know many (/most?) designers do.)

Also, I showed these to my wife, who can read & edit basic HTML, but not
PHP. I asked her if she'd be comfortable with moving the taxonomy terms
to display after the node contents. First seeing the PHP version, she
did not think she could safely do it. Then seeing the original, she
immediately point to the correct block of three lines, and said she'd
copy and past them to line 71. Perfect.

An unscientific test for sure, but I'd definitely side with the
traditional form.

Best,
Matt


Shai Gluskin wrote:

> Gang,
>
> Every tpl.php file that I've seen in any theme is written in html with
> php interspersed for putting in variables. I think part of the
> reasoning for this approach is that it would be easier for non-geek
> designers to read such pages.
>
> I want to challenge that. I think all those php open-close and all the
> "print" commands makes for very hard-to-read code. Tonight, as an
> experiment, I rewrote the node.tpl.php file from Zen from html to php.
> I think it is a lot easier to read. And it's sure a lot easier to comment.
>
> I pasted my rewritten version and the original from Zen onto a pastebin:
> http://pastebin.ca/1614186
>
> Anyway, I'd be curious what other's opinions are on this.
>
> best,
>
> Shai
> ------------------------------------------------------------------------
>
> _______________________________________________
> consulting mailing list
> consulting@...
> http://lists.drupal.org/mailman/listinfo/consulting
>  
_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.phpLooks Like

by Nancy Wichmann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Shai, I absolutely agree with you on the readability aspect. I, too, rewrote several tpl.php files before I stumbled across a post on DO somewhere that said the interspersed technique was as much as 4 times faster to execute. However, we still see "print" used exclusively when "echo" is faster...
 
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Parent Message unknown Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Shai Gluskin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gang,

Matt, very cool on the user testing.

Ultimately, it does come down to personal preference. Newbies wouldn't
know there is something different. If this is enough if an itch for me
I could put out a Zen clone with the tpl files re-written.

I want to research Michelle's suggestion that all PHP degrades
performance. I'm sceptacle of that.

Re Greg's point about the View-source less structured/ harder to read.
First off, the output when doing it HTML style is far from perfect.
And I think in a Firebug world, it's kind of moot, cause Firebug reads
the DOM of the doc and puts the HTML in perfect order, so the  raw
View-source isn't that important.

An interesting addition to Matt's user test would be to ask the user
to comment out a portion of the code, which is a really helpful thing
to do when experimenting. Very easy in PHP; a real pain in a mixed
PHP/HTML environment.

The Zen tpl files have a bunch of helpful documentation at the top. In
a PHP environment, the help could be interspersed throughout the file,
 close to relevant code. It would also be easy to add sample code
snippets that are commented out by default. Zen does that quite a bit
in template.php and in CSS files, but that is notably missing from the
tpl files.

Shai

On Monday, October 12, 2009, Nancy Wichmann <nan_wich@...> wrote:

>
>
>
>
>
> Shai,
> I absolutely agree with you on the readability aspect. I, too, rewrote several
> tpl.php files before I stumbled across a post on DO somewhere that said the
> interspersed technique was as much as 4 times faster to execute. However, we
> still see "print" used exclusively when "echo" is faster...
>
> Nancy E. Wichmann,
> PMP
> Injustice
> anywhere is a threat to justice everywhere. -- Dr. Martin L. King,
> Jr.
>
_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Sam Cohen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Shai,

When a designer is not involved I almost always use php only versions of tpl files, but I do find designers are much more comfortable with the mixed technique.

As to Matt's question about Dreamweaver, the assumption is correct, you cannot view the php only versions in "design view" where you can with the mixed method, however, given there is no css available to the tpl files in design view, I'm not sure designers would ever use design view, so it might not be an issue. 

What I do find a lot more readable in the mixed method is instead of all those <?php print $terms ?> statements is the simple <?=$terms ?> but I guess there's some good reason that method isn't used. 

Sam

On Mon, Oct 12, 2009 at 8:59 AM, Shai Gluskin <shai@...> wrote:
Gang,

Matt, very cool on the user testing.

Ultimately, it does come down to personal preference. Newbies wouldn't
know there is something different. If this is enough if an itch for me
I could put out a Zen clone with the tpl files re-written.

I want to research Michelle's suggestion that all PHP degrades
performance. I'm sceptacle of that.

Re Greg's point about the View-source less structured/ harder to read.
First off, the output when doing it HTML style is far from perfect.
And I think in a Firebug world, it's kind of moot, cause Firebug reads
the DOM of the doc and puts the HTML in perfect order, so the  raw
View-source isn't that important.

An interesting addition to Matt's user test would be to ask the user
to comment out a portion of the code, which is a really helpful thing
to do when experimenting. Very easy in PHP; a real pain in a mixed
PHP/HTML environment.

The Zen tpl files have a bunch of helpful documentation at the top. In
a PHP environment, the help could be interspersed throughout the file,
 close to relevant code. It would also be easy to add sample code
snippets that are commented out by default. Zen does that quite a bit
in template.php and in CSS files, but that is notably missing from the
tpl files.

Shai

On Monday, October 12, 2009, Nancy Wichmann <nan_wich@...> wrote:
>
>
>
>
>
> Shai,
> I absolutely agree with you on the readability aspect. I, too, rewrote several
> tpl.php files before I stumbled across a post on DO somewhere that said the
> interspersed technique was as much as 4 times faster to execute. However, we
> still see "print" used exclusively when "echo" is faster...
>
> Nancy E. Wichmann,
> PMP
> Injustice
> anywhere is a threat to justice everywhere. -- Dr. Martin L. King,
> Jr.
>
_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting


_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by samtresler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On a somewhat disconnected note, on highly customized themes, as a  
project manager or lead developer, you can plug a plain html file into  
the theme, and it 'works' if not dynamically.   Then you can assign a  
dev to go back and 'plug in' the php.  With the php-only approach you  
need to convert a plain html file into the new style.

I don't know how everyone else works, but whereever possible I get an  
html mockup from the designers, and it just doesn't make sense to add  
the extra step.  I suppose this approach is fine for a developer  
translating photoshop mockups, but I don't think it would be feasible  
after you scaled to having designs provided as html/css.

Thanks.

-Sam
_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Steve Ringwood :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One thing this discussion seems to miss is that there are both  
functions and  template files that can be used.
If you are going to use the  PHP approach,  using the function makes
more sense.


_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Shai Gluskin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Steve,

Can you give a little more detail here. To which function are you referring?

Shai
_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Ryan Cross-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Tue, Oct 13, 2009 at 12:09 AM, Sam Cohen <sam@...> wrote:

What I do find a lot more readable in the mixed method is instead of all those <?php print $terms ?> statements is the simple <?=$terms ?> but I guess there's some good reason that method isn't used. 


The syntax you refer to is called "short tags", and is not universally supported (it has to be turned on in your php config). I think there may also be arguments about performance on short tags, but the main issue is the cross platform support. 

This is also reflected in the coding standards, which may point to some more detailed discussions if interested.  

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting

Re: Challenging an Assumption About What an Easy tpl.php Looks Like

by Aaron Winborn-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://pastebin.ca/1616950 offers an alternative to that, using <<<OUTPUT ... OUTPUT; so you can just paste in the php variables to print.

I noticed that this tpl file uses a lot of PHP functionality besides printing variables, which, as I understand, is to be avoided where possible. Perhaps the Zen theme should be doing a lot of the t(' in ') and if statements in a template preprocess function anyway, to clean things a little better for theming?

Aaron

Shai Gluskin wrote:
Gang,

Every tpl.php file that I've seen in any theme is written in html with php interspersed for putting in variables. I think part of the reasoning for this approach is that it would be easier for non-geek designers to read such pages.

I want to challenge that. I think all those php open-close and all the "print" commands makes for very hard-to-read code. Tonight, as an experiment, I rewrote the node.tpl.php file from Zen from html to php. I think it is a lot easier to read. And it's sure a lot easier to comment.

I pasted my rewritten version and the original from Zen onto a pastebin:
http://pastebin.ca/1614186

Anyway, I'd be curious what other's opinions are on this.

best,

Shai

_______________________________________________ consulting mailing list consulting@... http://lists.drupal.org/mailman/listinfo/consulting


-- 
Aaron Winborn

Advomatic, LLC
http://advomatic.com/

Drupal Multimedia available in September!
http://www.packtpub.com/create-multimedia-website-with-drupal/book

My blog:
http://aaronwinborn.com/

_______________________________________________
consulting mailing list
consulting@...
http://lists.drupal.org/mailman/listinfo/consulting