| 1 |
--- |
| 2 |
title: Publish |
| 3 |
description: Publishes the given resource. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: nil |
| 9 |
signatures: [RESOURCE.Publish] |
| 10 |
--- |
| 11 |
|
| 12 |
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}} |
| 13 |
|
| 14 |
The `Publish` method on a `Resource` object writes the given resource to the [`publishDir`][]. |
| 15 |
|
| 16 |
This example uses [`resources.FromString`][] to create a resource from a string, then publishes it: |
| 17 |
|
| 18 |
```go-html-template {file="layouts/baseof.html"} |
| 19 |
{{ $content := printf "Contact: mailto:%s\n" site.Params.email }} |
| 20 |
{{ with resources.FromString ".well-known/security.txt" $content }} |
| 21 |
{{ .Publish }} |
| 22 |
{{ end }} |
| 23 |
``` |
| 24 |
|
| 25 |
The `Permalink` and `RelPermalink` methods also publish a resource. `Publish` is a convenience method for publishing without a return value. For example, this: |
| 26 |
|
| 27 |
```go-html-template |
| 28 |
{{ $resource.Publish }} |
| 29 |
``` |
| 30 |
|
| 31 |
Instead of this: |
| 32 |
|
| 33 |
```go-html-template |
| 34 |
{{ $noop := $resource.Permalink }} |
| 35 |
``` |
| 36 |
|
| 37 |
To publish a resource within a pipeline, use the [`resources.Publish`][] function instead. |
| 38 |
|
| 39 |
[`publishDir`]: /configuration/all/#publishdir |
| 40 |
[`resources.FromString`]: /functions/resources/fromstring/ |
| 41 |
[`resources.Publish`]: /functions/resources/publish/ |