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

Martin Kutschker masi-no at spam-typo3.org
Tue Apr 7 10:07:08 CEST 2009


Bastian Waidelich schrieb:
> Martin Kutschker wrote:
> 
> Hi Masi,
> 
>> Cumbersome.
> 
> I agree
>     '<em>' . $this->value . '</em>';
> or
>     "<em>{$this->value}</em>"
> is nicer than
>     $tag = new Tag('em', $this->value); // or rather some
> t3lib_div::makeInstanceClassName hassle
>     $tag->render();
> 
> But I'm especially talking about more complex constructions that can't
> be put in one line. Like this one (taken from the select view helper):

[example snipped]

Makes much more sense to me now.

> But it's not only about readability or stability but reusability:
> Instead of copying all the tag-creation code from a view helper to
> create your custom version, you could extend the view helper and only
> modify or add some attributes of the underlying tag:
> 
> class LinkViewHelper extends TagBasedViewHelper {
>     public function render($uri) {
>         $this->tag->addAttribute('href', $uri);
>     }
> }
> 
> class SpeciallinkViewHelper extends LinkViewHelper {
>     public function render() {
>         $this->tag->addAttribute('rel', 'I\'m special');
>     }
> }

Nice, idea.

I see now that there are uses cases for such a class.

Masi


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