repetition structures in html

177 views
Skip to first unread message

Joubert Guimarães de Assis

unread,
Jan 24, 2013, 6:55:08 AM1/24/13
to php-f...@googlegroups.com
There is a standard for opening and closing of loops when the source code is mixed with html?

I see this so much I put the link http://pastebin.com/Ls4VPGzN
But if the html code for many lines in the middle, at the end you do not know if the keys that correspond repeating structure


Thinking about this, I imagine it would be better this way http://pastebin.com/MGasqgX1
because then you know that at this point ending the repeating structure


This way I implement this correct? I would like to discuss more about it.

ps: sorry my bad english

Larry Garfield

unread,
Jan 24, 2013, 11:26:57 AM1/24/13
to php-f...@googlegroups.com
Using the alternate syntax for control structures[1] when mixing PHP and
HTML template-style is the de facto standard I've seen, and it is the de
jure standard when dealing with Drupal PHP templates. Although we
structure it slightly differently:

<?php if ($blah): ?>
<div><?php echo $blah; ?>
<?php endif; ?>

That way it's more compact and the control structures read more like tags.

That's assuming you're in a template-esque file. If you're in a
non-template-esque file, you shouldn't be breaking out to HTML in the
first place. If you need to format a large block of HTML while in a
mostly-PHP file, use HEREDOC[2] instead.

[1] http://php.net/manual/en/control-structures.alternative-syntax.php
[2]
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

--Larry Garfield

On 1/24/13 5:55 AM, Joubert Guimar�es de Assis wrote:
> There is a standard for opening and closing of loops when the source
> code is mixed with html?
>
> I see this so much I put the link http://pastebin.com/Ls4VPGzN
> But if the html code for many lines in the middle, at the end you do not
> know if the keys that correspond repeating structure
>
>
> Thinking about this, I imagine it would be better this way
> http://pastebin.com/MGasqgX1
> because then you know that at this point ending the repeating structure
>
>
> This way I implement this correct? Iwould like to discuss more about it.
>
> ps: sorry my bad english
>
> --
>
>

Will Ayers

unread,
Jan 28, 2013, 11:20:03 AM1/28/13
to php-f...@googlegroups.com
I agree with Larry as well. The use of endif; and endforeach; instead of brackets make it much easier to read, shift through and find the ending points of loops;


On Thursday, January 24, 2013 9:26:57 AM UTC-7, Larry Garfield wrote:
Using the alternate syntax for control structures[1] when mixing PHP and
HTML template-style is the de facto standard I've seen, and it is the de
jure standard when dealing with Drupal PHP templates.  Although we
structure it slightly differently:

<?php if ($blah): ?>
   <div><?php echo $blah; ?>
<?php endif; ?>

That way it's more compact and the control structures read more like tags.

That's assuming you're in a template-esque file.  If you're in a
non-template-esque file, you shouldn't be breaking out to HTML in the
first place.  If you need to format a large block of HTML while in a
mostly-PHP file, use HEREDOC[2] instead.

[1] http://php.net/manual/en/control-structures.alternative-syntax.php
[2]
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

--Larry Garfield

Reply all
Reply to author
Forward
0 new messages