On 13.05.2013 21:26, Max Semenik wrote:
Hi, I've seen recently a lot of code like this:

$html = Html::openElement( 'div', array( 'class' => 'foo' )
     . Html::rawElement( 'p', array(),
         Html::element( 'span', array( 'id' => $somePotentiallyUnsafeId ),
             $somePotentiallyUnsafeText
         )
     )
     . Html::closeElement( 'div' );

IMO, cruft like this makes things harder to read and adds additional
performance overhead. It can be simplified to

$html = '<div class="foo'><p>'
     . Html::rawElement( 'p', array(),
         Html::element( 'span', array( 'id' => $somePotentiallyUnsafeId ),
             $somePotentiallyUnsafeText
         )
     )
     . '</p></div>';

What's your opinion, guys and gals?

With php 5.4+ array syntax the code will be even more compact (comparable to raw html but structured easily manipulated data) [ '@tag' => 'div', 'class' => 'foo', [ '@tag' => 'p', [ '@tag' => 'span', 'id' => $id, $text ], '#comment' => $comment ] ];

Placing language operators into template itself like

{% for user in users %}

does not separate html data from code well enough. Template language always 
will be more limited comparing to processing via PHP classes.
Dmitriy


_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to