I have read several posts here on multi theming and would like your advice as perhaps I overlook the obvious.
I have a travel web site with city information where each city has its own page. I am now creating an itinerary builder which makes ajax calls to these pages. However, in the case of the latter I just need the bare content, not the header, footer, images etc. i.e. I would need the scrape the page to get the bare content.
One would expect the json output to be simlar to the html version right?
My directory structure is /content/english/states/state/cities/city/etc
e.g uttar-pradesh/cities/agra/hotels
In states my list.json.json lists all the states as expected just like the html version. But from state onwards it lists the data of the directory ahead: e.g. the best places in that state rather than the single state as the html version does. Any idea what I may be doing wrong?
list.json.json file:
{{ define “response” }}
{
{{ with eq .Kind “section”}}
“section” : “{{ $.Section }}”,
{{ end }}
“count” : “{{ len .Data.Pages }}”
,“items” : [
{{ range $i, $e := .Data.Pages }}
{{ if $i }}, {{ end }}{{ .Render “item” }}
{{ end }}
]
}
{{ end }}
hugo v.0.75.1
github: git@github.com:ourmaninindia/odyssey-tours.git
I am a bit puzzled by your reference, I only have list pages here and my list.html page uses the same Data.Pages variable as my json mentioned earlier yet .
list.htlm:
{{- $paginator := .Paginate .Data.Pages }}
{{- range $paginator.Pages }}
{{- .Render “summary” }}
{{- end }}
{{- end }}
The json in the root of the section shows “permalink” : “/states/andaman-and-nicobar/” + 30 other states (fine)
The next directory shows “permalink” : “/states/uttar-pradesh/cities/” while I expected to see “permalink” : “/states/uttar-pradesh/” (as did the html version)
/states/uttar-pradesh is a list type page - content comes from its _index.md. /states/uttar-pradesh/cities/ is also a list type page - content comes from its _index.md.
Therefore, for the index.json output, both the States and the Cities render from ./layouts/_default/list.json.json, which is doing exactly the same thing for all of them - it’s looping through the .Data.Pages collection for that _index page.
The output json on /states/uttar-pradesh/index.json is showing you exactly what you asked it to - the collection of pages (so happens there is only the 1 sub-dir “Cities”) underneath uttar-pradash.
But you’re actually wanting NOT to loop through the .Data.Pages collection, and instead put out only the CURRENT page’s info. Basically, you’re wanting the same json structure to mean different things depending on where you are in the hierarchy. You can do this, but it’s going to be up to you to code this into your list.json.json template so that it handles each case differently depending on what you want the output to be on each level.