0 follower

Trait Yiisoft\Html\Tag\Base\TagContentTrait

Implemented byYiisoft\Html\Tag\A, Yiisoft\Html\Tag\Address, Yiisoft\Html\Tag\Article, Yiisoft\Html\Tag\Aside, Yiisoft\Html\Tag\B, Yiisoft\Html\Tag\Base\TableCellTag, Yiisoft\Html\Tag\Body, Yiisoft\Html\Tag\Button, Yiisoft\Html\Tag\Caption, Yiisoft\Html\Tag\Code, Yiisoft\Html\Tag\CustomTag, Yiisoft\Html\Tag\Datalist, Yiisoft\Html\Tag\Div, Yiisoft\Html\Tag\Em, Yiisoft\Html\Tag\Fieldset, Yiisoft\Html\Tag\Footer, Yiisoft\Html\Tag\Form, Yiisoft\Html\Tag\H1, Yiisoft\Html\Tag\H2, Yiisoft\Html\Tag\H3, Yiisoft\Html\Tag\H4, Yiisoft\Html\Tag\H5, Yiisoft\Html\Tag\H6, Yiisoft\Html\Tag\Header, Yiisoft\Html\Tag\Hgroup, Yiisoft\Html\Tag\Html, Yiisoft\Html\Tag\I, Yiisoft\Html\Tag\Label, Yiisoft\Html\Tag\Legend, Yiisoft\Html\Tag\Li, Yiisoft\Html\Tag\Nav, Yiisoft\Html\Tag\Noscript, Yiisoft\Html\Tag\Option, Yiisoft\Html\Tag\P, Yiisoft\Html\Tag\Pre, Yiisoft\Html\Tag\Section, Yiisoft\Html\Tag\Small, Yiisoft\Html\Tag\Span, Yiisoft\Html\Tag\Strong, Yiisoft\Html\Tag\Td, Yiisoft\Html\Tag\Textarea, Yiisoft\Html\Tag\Th, Yiisoft\Html\Tag\Title

Adds functionality for processing with tag content.

Protected Methods

Hide inherited methods

Method Description Defined By
generateContent() Yiisoft\Html\Tag\Base\TagContentTrait

Method Details

Hide inherited methods

addContent() public method

public Yiisoft\Html\Tag\Base\TagContentTrait addContent ( string|\Stringable $content )
$content string|\Stringable

Tag content.

                final public function addContent(string|Stringable ...$content): static
{
    $new = clone $this;
    $new->content = array_merge($new->content, array_values($content));
    return $new;
}

            
content() public method

public Yiisoft\Html\Tag\Base\TagContentTrait content ( string|\Stringable $content )
$content string|\Stringable

Tag content.

                final public function content(string|Stringable ...$content): static
{
    $new = clone $this;
    $new->content = array_values($content);
    return $new;
}

            
doubleEncode() public method

public Yiisoft\Html\Tag\Base\TagContentTrait doubleEncode ( boolean $doubleEncode )
$doubleEncode boolean

Whether already encoded HTML entities in tag content should be encoded. Defaults to true.

                final public function doubleEncode(bool $doubleEncode): static
{
    $new = clone $this;
    $new->doubleEncode = $doubleEncode;
    return $new;
}

            
encode() public method

public Yiisoft\Html\Tag\Base\TagContentTrait encode ( boolean|null $encode )
$encode boolean|null

Whether to encode tag content. Supported values:

  • null: stringable objects that implement interface {@see \Yiisoft\Html\NoEncodeStringableInterface} are not encoded, everything else is encoded;
  • true: any content is encoded;
  • false: nothing is encoded. Defaults to null.

                final public function encode(?bool $encode): static
{
    $new = clone $this;
    $new->encode = $encode;
    return $new;
}

            
generateContent() protected method

protected string generateContent ( )
return string

Obtain tag content considering encoding options {@see \Yiisoft\Html\Tag\Base\encode()}.

                final protected function generateContent(): string
{
    $content = '';
    foreach ($this->content as $item) {
        if ($this->encode || ($this->encode === null && !($item instanceof NoEncodeStringableInterface))) {
            $item = Html::encode($item, $this->doubleEncode);
        }
        $content .= $item;
    }
    return $content;
}