src/Web/View.php
public function registerJsVar($name, $value, $position = self::POS_HEAD)
    {
        $js = sprintf('var %s = %s;', $name, Json::htmlEncode($value));
        $this->registerJs($js, $position, $name);
    }
public function registerJsVar($name, $value, $position = self::POS_HEAD)
    {
        $js = sprintf('var %s = %s;', $name, Json::htmlEncode($value));
        $this->registerJs($js, $position, $name);
    }
Registers a JS code block defining a variable. The name of variable will be
used as key, preventing duplicated variable names.

@param string $name Name of the variable
@param array|string $value Value of the variable
@param int $position the position in a page at which the JavaScript variable should be inserted.
The possible values are:

- [[POS_HEAD]]: in the head section. This is the default value.
- [[POS_BEGIN]]: at the beginning of the body section.
- [[POS_END]]: at the end of the body section.
- [[POS_LOAD]]: enclosed within jQuery(window).load().
Note that by using this position, the method will automatically register the jQuery js file.
- [[POS_READY]]: enclosed within jQuery(document).ready().
Note that by using this position, the method will automatically register the jQuery js file.