Skip to content

Commit

Permalink
Better explanation of unique asset identifiers. Thanks pagekit#74. Close
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian committed Jun 20, 2016
1 parent 9032d6d commit 8e3b42d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions developer/views-templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ To generate a route to a static asset, use the `getStatic` method of the `UrlPro
```

### Include CSS in view file
To include a CSS file in your view, call the `style helper` from the `View`. You can define its dependencies through the second parameter.
To include a CSS file in your view, call the `style` helper from the `View`.

```php
$view->style($id, $path [, $dependencies ])
```

The first parameter is a unique identifier for the stylesheet. If you use the same identifier for multiple stylesheets, Pagekit will only include the last one. The second parameter is the path of the stylesheet where you can use `theme:` as a reference to the root directory of the 'theme' package. You can define its dependencies through the optional third parameter.

Example:

```
<?php $view->style('theme', 'theme:css/theme.css') ?>
Expand All @@ -120,15 +128,23 @@ To include a CSS file in your view, call the `style helper` from the `View`. You
**Note** This will not directly output the required line in HTML. Instead, it will add the CSS file to the Pagekit Asset Manager. The stylesheet will be included in the `<head>` section of your theme.

### Include JS in view file
To include a JavaScript file in your template, call the `script helper` from the `View`. You can define its dependencies through the second parameter.
To include a JavaScript file in your template, call the `script` helper from the `$view` object which works exactly like the `style` helper.

```php
$view->script($id, $path [, $dependencies ])
```

The first parameter is a unique identifier for the script asset. If you use the same identifier for multiple scripts, Pagekit will only include the last one. The second parameter is the path of the script where you can use `theme:` as a reference to the root directory of the 'theme' package. You can define its dependencies through the optional third parameter.

Example:

```
<?php $view->script('theme', 'theme:js/theme.js') ?>
<?php $view->script('theme', 'theme:js/theme.js', 'jquery') ?>
<?php $view->script('theme', 'theme:js/theme.js', ['jquery', 'uikit']) ?>
```

**Note** Internally, `style()` and `script()` each work with their own Asset Manager. As these are separate from each other, you can assign the same name to a CSS and JS file without conflict (both called `theme` in the above example).
**Note** Internally, `style()` and `script()` each work with their own Asset Manager. As these are separate from each other, you can assign the same name to a CSS and JS file without conflict (both called `theme` in the above example). However, no two scripts or stylesheets may have the same identifier. For example, when adding two stylesheets, one could be named 'theme', and the other 'custom'.

### Async and deferred script execution

Expand Down

0 comments on commit 8e3b42d

Please sign in to comment.