Skip to content

Add support for inline partials in content adapters #14480

@rbnvrw

Description

@rbnvrw

After discussion in https://discourse.gohugo.io/t/using-inline-partials-in-content-adapters/56693 I'd like to propose the following feature (text copied from that post):

I’m experimenting with Content Adapters, specifically I’d like to be able to use Go templates and pass these as the content to the .AddPagemethod. I came up with a simple example based on a combination of the examples in https://gohugo.io/content-management/content-adapters/#addpage and https://gohugo.io/functions/go-template/define/#article as follows, which I added to content/test/_content.gotmpl:

{{ define "_partials/inline/foo.html" }}
  {{ printf "The _Hunchback of Notre Dame_ was written by Victor Hugo in %v." .answer }}
{{ end }}

{{ $content := dict
  "mediaType" "text/markdown"
  "value" (partial "inline/foo.html" (dict "answer" 1831))
}}

{{ $page := dict
  "content" $content
  "kind" "section"
  "path" "../test"
  "title" "The Hunchback of Notre Dame"
}}

{{ .AddPage $page }}

Unfortunately, this results in the following error message:

error building site: 
process: readAndProcessContent: "/content/test/_content.gotmpl:7:11": 
template: /content/test/_content.gotmpl:7:11: 
executing "/content/test/_content.gotmpl" at <partial "inline/foo.html" (dict "answer" 1831)>: 
error calling partial: partial "inline/foo.html" not found

According to @bep this is currently not supported, but could possibly be added.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions