diff --git a/docs/guide/view.md b/docs/guide/view.md index 7d90fc5..932b789 100644 --- a/docs/guide/view.md +++ b/docs/guide/view.md @@ -183,8 +183,32 @@ page. We're using third argument so one of the views could override it. ### Registering scripts +With View object you can register scripts. There are two dedicated methods for it: `registerScript` for inline scripts +and `registerJsFile` for external scripts. Inline scripts are useful for configuration and dynamically generated code. +The method for adding these can be used as follows: +```php +$this->registerScript("var options = ".json_encode($options).";", View::POS_END, 'my-options'); +``` + +First argument is the actual code where we're converting a PHP array of options to JavaScript one. Second argument +determines where script should be in the page. Possible values are: + +- `View::POS_HEAD` for head section. +- `View::POS_BEGIN` for right after opening `
`. +- `View::POS_END` for right before closing ``. +- `View::POS_READY` for executing code on document `ready` event. This one registers jQuery automatically. + +The last argument is unique script ID that is used to identify code block and replace existing one with the same ID +instead of adding a new one. +External script can be added like the following: + +```php +$this->registerJsFile('http://example.com/js/main.js'); +``` + +Same as with external CSS it's preferred to use asset bundles for external scripts. ### Registering asset bundles @@ -198,6 +222,40 @@ frontend\config\AppAsset::register($this); ### Layout +A layout is a very convenient way to represent the part of the page that is common for all or at least for most pages +generated by your application. Typically it includes `` section, footer, main menu and alike elements. +You can fine a fine example of the layout in a [basic application template](apps-basic.md). Here we'll review the very +basic one without any widgets or extra markup. + +```php + +beginPage(); ?> + + + + +