public function addVariable(string $name, $value)
    {
        // Convert value to something usable in the output
        if (WF::is_array_like($value))
        {
            $value = WF::to_array($value);
        }
        elseif (is_subclass_of($value, JSONSerializable::class))
        {
            $value = $value->jsonSerialize();
        }
        elseif (!is_scalar($value))
        {
            throw new InvalidArgumentException("Invalid value provided for JS variable $name");
        }

        $this->inline_variables[$name] = $value;
        return $this;
    }
public function addVariable(string $name, $value)
    {
        // Convert value to something usable in the output
        if (WF::is_array_like($value))
        {
            $value = WF::to_array($value);
        }
        elseif (is_subclass_of($value, JSONSerializable::class))
        {
            $value = $value->jsonSerialize();
        }
        elseif (!is_scalar($value))
        {
            throw new InvalidArgumentException("Invalid value provided for JS variable $name");
        }

        $this->inline_variables[$name] = $value;
        return $this;
    }
public function addVariable ( string $ name , $ value ) { // Convert value to something usable in the output if ( WF :: is_array_like ( $ value ) ) { $ value = WF :: to_array ( $ value ) ; } elseif ( is_subclass_of ( $ value , JSONSerializable :: class ) ) { $ value = $ value -> jsonSerialize ( ) ; } elseif ( ! is_scalar ( $ value ) ) { throw new InvalidArgumentException ( "Invalid value provided for JS variable $name" ) ; } $ this -> inline_variables [ $ name ] = $ value ; return $ this ; }
Add a javascript variable to be added to the output document. A script will
be generated to definie these variables on page load.
@param string $name The name of the variable. Must be a valid javascript
variable name.
@param mixed The value to set. Should be scalar, array or JSONSerializable
Add a javascript variable to be added to the output document . A script will be generated to definie these variables on page load .