Hello,
I want to index some Pages as JSON.
section1.html:
`
…
`
`var something = [
{{ range .Data.Pages }}
{{ .Render "list-item-expanded-js" }}
{{end }}
]`
`
...
`
list-item-expanded-js.html:
`{
titel:"{{ .Title }}",{{ if isset .Params "img" }}
image:"{{ .Site.BaseURL }}img/{{ .Params.img }}"{{ end }},
text:"{{ .Summary }}",
link:"{{ .Permalink }}"
},
`
My Problem is that renders quotes to \" and line breaks to \n, like:
`"{\ntitel:\"Tanzen\",\nimage:\"/img/flower.jpg\",\ntext:\"Hier könnte man Angebote eintragen.\",\nlink:\"/angebote/Tanzen/\"\n},\n\n\n\n"
"{\ntitel:\"Singen\",\nimage:\"/img/Wikipedia.png\",\ntext:\"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\",\nlink:\"/angebote/Singen/\"\n},\n\n\n\n"`"
If there is no `` between them it function and renders it correctly. And i dont use lunrjs, but something like that.
I new here and correct me, if i done something wrong and my marks in English are not the best.
Thanks!
@PLE_Schwabauer There are a few places to look since I’m still a little unclear on your desired output…
Hi rdwatters,
I searched hours at Google, and found also your linked Forum Post. I have tried already jsonify, but that makes the same as a <script>
between them. The solution is as you say safeJS:
{{ range .Data.Pages }} {{ .Render "list-item-expanded-js" | safeJS }} {{ end }}
Thanks a lot! Sorry for bad English.
1 Like
@PLE_Schwabauer Glad it worked out, but I can’t take any credit: I just pointed you to the docs, after all.
P.S. Never apologize for poor English. I’m an American and you speak one more language than I do
Happy Hugo-ing.