Skip to content

Commit

Permalink
Document link tag helper and improve Resources docs (#6739)
Browse files Browse the repository at this point in the history
  • Loading branch information
scleaver authored Jul 29, 2020
1 parent b8f3684 commit 0e05751
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/docs/reference/modules/Liquid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ Using `helper` invokes the `validation_for` tag helper of ASP.NET Core with `spa

### `link`

Invokes the `link` tag helper from the `Orchard.ResourceManagement` package.
Invokes the `link` tag helper from the `Orchard.ResourceManagement` package. [see this section](../Resources/README.md#link-tag)

### `meta`

Expand Down
41 changes: 37 additions & 4 deletions src/docs/reference/modules/Resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ resourceManager.AppendMeta(new MetaEntry { Name = "keywords", Content = "orchard

From your module, in the `_ViewImports.cshtml` or your view, add `@addTagHelper *, OrchardCore.ResourceManagement`.

#### Register a named script
#### Register a named script or stylesheet

This example registers the script named `bootstrap` and all its dependencies (jquery).

Expand All @@ -189,6 +189,10 @@ This example registers the script named `bootstrap` and all its dependencies (jq

And for a stylesheet:

``` liquid tab="Liquid"
{% style name:"bootstrap" %}
```

``` html tab="Razor"
<style asp-name="bootstrap"></style>
```
Expand Down Expand Up @@ -232,7 +236,7 @@ You can append a version hash that will be calculated, and calculation cached, a

##### Specify location

By default all scripts are rendered in the footer. You can override it like this:
Specify a location the script should load using `at`, for example `Foot` to rendered wherever the `FootScript` helper is located or `Head` to render with the `HeadScript` [See Foot Resources](#foot-resources). If the location is not specified, the script will be inserted wherever it is placed (inline).

``` liquid tab="Liquid"
{% script name:"bootstrap", at:"Foot" %}
Expand All @@ -242,7 +246,7 @@ By default all scripts are rendered in the footer. You can override it like this
<script asp-name="bootstrap" at="Foot"></script>
```

Styles, however, are always injected in the header section of the HTML document.
Link and styles tag helpers always inject into the header section of the HTML document regardless of the `at` value.

#### Inline definition

Expand Down Expand Up @@ -365,6 +369,35 @@ The style block will only be injected once based on its name and can optionally
}
</style>
```
#### Link tag

A link tag is used to define the relationship between the current document and an external resource such as a favicon or stylesheet. For a stylesheet, however, use the [style helper](#register-a-named-script).

``` liquid tab="Liquid"
{% link rel:"icon", type:"image/png", sizes:"16x16", src:"~/MyTheme/favicon/favicon-16x16.png" %}
```

``` html tab="Razor"
<link asp-src="~/MyTheme/favicon/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16" />
```

Output

```text
<link href="/MyTheme/favicon/favicon-16x16.png" rel="icon" sizes="16x16" type="image/png" />
```

##### Using a file in the media library
If you wish to use files contained in the media library when using the link tag helper, you can use the `AssetUrl` helper directly in razor but in liquid you will need to first assign the filter result to a variable like so to generate the correct URL:

``` liquid tab="Liquid"
{% assign image_url = 'favicon/favicon-16x16.png' | asset_url %}
{% link rel:"icon", type:"image/png", sizes:"16x16", src:image_url %}
```

``` html tab="Razor"
<link asp-src=@Orchard.AssetUrl("favicon/favicon-16x16.png") rel="icon" type="image/png" sizes="16x16" />
```

#### Meta tags

Expand Down Expand Up @@ -434,4 +467,4 @@ These should be rendered at the bottom of the `<body>` section.

### Logging

If you register a resource by name and it is not found this will be logged as an error in your `App_Data/Logs` folder.
If you register a resource by name and it is not found this will be logged as an error in your `App_Data/Logs` folder.

0 comments on commit 0e05751

Please sign in to comment.