[TYPO3-team-core-v5] RFC: TagBuilder

Martin Kutschker masi-no at spam-typo3.org
Sun Apr 5 20:50:39 CEST 2009


Bastian Waidelich schrieb:
> Hi everybody,
> 
> Whenever we need to create HTML (or XML) tags from PHP (e.g. in the
> tag-based view helpers for Fluid) we end up concatenating long strings
> like this:
> 
> return '<a href="' . $uri . '" ' . $this->renderTagAttributes() . '>' .
> $this->renderChildren() . '</a>';
> 
> This is not very readable and very error-prone.
> I think, it would be nice, to have some kind of Tag-builder, so that you
> could write s.th. like:*
> 
> $tag = new Tag('a');
> $tag->addAttribute('href', $uri);
> $tag->addAttributes($this->tagAttributes());
> $tag->setContent($this->renderChildren());
> return $tag->render();
> 
> I think that could be a neat little class for TYPO3 v4 _and_ FLOW3.
> What do you think,
> Useful?

Cumbersome.

While I agree that long lists of tags with many attributes get tiresome
written in the way you mentioned, I don't think you solve the problem
with your solution. I cannot imagine that I would like to call 5
functions just to create a single tag.

I know that in the TYPO3 world the double quote is shunned but I started
to use double quotes strings and HEREDOC more frequently. If you you use
the {$var} syntax with an editor that is able to hilight the variable
parts of a string this is best in terms of readability.

I'm sorry to say, but also in this respect I see no improvement by your
suggestion.

Masi


More information about the TYPO3-team-core-v5 mailing list