FluidTYPO3\Vhs\Traits\TagViewHelperTrait::renderTag PHP Method

renderTag() protected method

Renders the provided tag with the given name and any (additional) attributes not already provided as arguments.
protected renderTag ( string $tagName, mixed $content = null, array $attributes = [], array $nonEmptyAttributes = ['id', 'class'] ) : string
$tagName string
$content mixed
$attributes array
$nonEmptyAttributes array
return string
    protected function renderTag($tagName, $content = null, array $attributes = [], array $nonEmptyAttributes = ['id', 'class'])
    {
        $trimmedContent = trim((string) $content);
        $forceClosingTag = (bool) $this->arguments['forceClosingTag'];
        if (true === empty($trimmedContent) && true === (bool) $this->arguments['hideIfEmpty']) {
            return '';
        }
        if ('none' === $tagName || true === empty($tagName)) {
            // skip building a tag if special keyword "none" is used, or tag name is empty
            return $trimmedContent;
        }
        $this->tag->setTagName($tagName);
        $this->tag->addAttributes($attributes);
        $this->tag->forceClosingTag($forceClosingTag);
        if (null !== $content) {
            $this->tag->setContent($content);
        }
        // process some attributes differently - if empty, remove the property:
        foreach ($nonEmptyAttributes as $propertyName) {
            $value = $this->arguments[$propertyName];
            if (true === empty($value)) {
                $this->tag->removeAttribute($propertyName);
            } else {
                $this->tag->addAttribute($propertyName, $value);
            }
        }
        return $this->tag->render();
    }