resources.Concat
Returns a resource created by concatenating the given slice of resources.
- Syntax
- resources.Concat TARGETPATH SLICE
- Returns
- resource.Resource
This works with global resources, page resources, and remote resources.
Usage
The resources.Concat function returns a resource created by concatenating the given slice of resources, caching the result using the target path as its cache key. Use it to bundle text resources such as JavaScript and CSS files. Each resource must have the same media type.
Hugo publishes the resource to the target path when you call its Publish, Permalink, or RelPermalink method, or pass it to the resources.Publish function.
Arguments
TARGETPATH- (
string) The path of the published resource, relative to the site root. SLICE- (
resource.Resources) A slice of the resources to concatenate, in order. Thecollections.Slicefunction returns this type when every element is a resource, as do theresources.ByTypeandresources.Matchfunctions. Other slices cause an error, including:- A slice that contains a
nilelement, such as the value returned by theresources.Getfunction when it cannot find the file. - The slice returned by the
collections.Applyfunction, which is always of type[]any.
To create a slice of resources from a list of file paths, use the
collections.Appendfunction within arangeloop, as shown in the examples. - A slice that contains a
Examples
{{ $plugins := resources.Get "js/plugins.js" }}
{{ $global := resources.Get "js/global.js" }}
{{ $js := slice $plugins $global | resources.Concat "js/bundle.js" }}Creating the slice from a list of file paths, skipping files that do not exist:
{{ $paths := slice "js/plugins.js" "js/global.js" }}
{{ $resources := slice }}
{{ range $paths }}
{{ with resources.Get . }}
{{ $resources = $resources | append . }}
{{ end }}
{{ end }}
{{ $js := resources.Concat "js/bundle.js" $resources }}Last updated:
November 8, 2026
:
content: Remove categories from front matter (1cc1dd83a)
Improve this page