Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render "li" returns html instead of json #5628

Closed
xlegs opened this issue Jan 21, 2019 · 2 comments
Closed

Render "li" returns html instead of json #5628

xlegs opened this issue Jan 21, 2019 · 2 comments

Comments

@xlegs
Copy link

xlegs commented Jan 21, 2019

I want Hugo to generate a JSON API alongside my pages. I am using the output formats feature, and the following layout templates in layouts/_default/

baseof.json.json

{
    "data": {{ block "main" . }}{{ end }} 
}

single.json.json

{{ define "main" }}

{{ .Render "li" }}

{{end}}

li.json.json

{
    "name": "{{ .Title }}",
    "location" : "{{ .Params.Location }}",
    "website" : "{{ .Params.Website }}",
    "logo" : "{{ .Params.Logo }}"
}

list.json.json

{{ define "main" }}

{{ range $index, $e := .Data.Pages }}
    {{ if $index }}, {{ end }}
    {{ .Render "li" }}
{{ end }}

{{end}}

Rendering the html works fine. It only fails when outputing a list of json objects.

Output for single

{
    "data": 

{
    "name": "A",
    "location" : "A",
    "website" : "A",
    "logo" : "/img/uploaded/logo.png"
}

}

Output for list

{
    "data": 
    
    <a href="/universities/a/" class="no-underline pa3 bg-grey-1 br1 mb2 db raise w-100">
	<h2 class="f3 b lh-title mb1 primary">A</h2>
	<p class="mid-gray lh-title mb2">Mon, Jan 1, 0001</p>
	<p class="mb0"></p>
	<p class="link b dib black mb0">Read more →</p>
</a>

    , 
    <a href="/universities/b/" class="no-underline pa3 bg-grey-1 br1 mb2 db raise w-100">
	<h2 class="f3 b lh-title mb1 primary">A</h2>
	<p class="mid-gray lh-title mb2">Mon, Jan 1, 0001</p>
	<p class="mb0"></p>
	<p class="link b dib black mb0">Read more →</p>
</a>

}

For whatever reason, the output for list renders the li.html template, but the json template is correctly rendered when rendering a single. This is inconsistent behavior.

Can anyone look into this?
Thanks

@bep bep added the Duplicate label Jan 21, 2019
@bep
Copy link
Member

bep commented Jan 21, 2019

#5090

@bep bep closed this as completed Jan 21, 2019
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants