T
T
Teran1232017-01-26 00:36:58
Yii
Teran123, 2017-01-26 00:36:58

Yii2 ActiveField how to add new {tag} to template?

Hello. Is it possible to add your own {tag} to the template without severe hemorrhoids?
There is a code, you need to add {icon}, and assign it by field(...)->icon('clock'), for example.

$form = ActiveForm::begin([
    'id' => 'login-form',
    'action' => '/login',
    'options' => ['class' => 'form-horizontal'],
    'fieldConfig' => [
        'template' => "<div class=\"col-lg-12\">
            <span class=\"fa fa-{icon} input-icon\"></span>
            {input}
        </div>\n<div class=\"col-lg-12\">{error}</div>",
    ],
]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-01-26
@Teran123

Goodnight.
What do you mean by "strong hemorrhoids"?
The ActiveField class has a public function render() method

public function render($content = null)
    {
        if ($content === null) {
            if (!isset($this->parts['{input}'])) {
                $this->textInput();
            }
            if (!isset($this->parts['{label}'])) {
                $this->label();
            }
            if (!isset($this->parts['{error}'])) {
                $this->error();
            }
            if (!isset($this->parts['{hint}'])) {
                $this->hint(null);
            }
            $content = strtr($this->template, $this->parts);
        } elseif (!is_string($content)) {
            $content = call_user_func($content, $this);
        }
        return $this->begin() . "\n" . $content . "\n" . $this->end();
    }

And there are a bunch of methods like public function input() that also generate different tags.
I think that if you redefine it, add what you want, then you can add your own tag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question