About Data-Driven Content
===
{{ $dataJ := getJSON “url” }}
I’d like to change json url each page.
ex)
{{ dataJ := getJSON "{{ .Param “json_url” }}" }}
is error.
===
Is there the way to change json url each page?
===
When I save edit, $ is disappeared.
doesn’t this work?
{{ $dataJ := getJSON ($.Param "json_url") }}
1 Like
Hi,
doesn’t this work?
It works
Thank you for your quick reply!
1 Like
maiki
June 15, 2018, 7:16pm
4
1 Like
Could you tell me how to change only part of json_url?
ex) YOUR_PLACE_ID
https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY
https://developers.google.com/places/web-service/details
===
My error is as follows.
error1.
{{ $dataJ := getJSON “https://maps.googleapis.com/maps/api/place/details/json?placeid= {{ .Param “place_id” }}&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
===
error2.
{{ $dataJ := getJSON “https://maps.googleapis.com/maps/api/place/details/json?placeid= ” “{{ .Param “place_id” }}” “&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
===
error3.
{{ $dataJ := getJSON “https://maps.googleapis.com/maps/api/place/details/json?placeid= ( .Param “place_id” )&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
===
error4.
{{ $dataJ := getJSON “https://maps.googleapis.com/maps/api/place/details/json?placeid= ” “( .Param “place_id” )” “&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
it’s not clear to me what your error is, but you keep getting the {{
mixed up in the code.
I see this:
{{ $dataJ := getJSON “https://maps.googleapis.com/maps/api/place/details/json?placeid={{ .Param “place_id” }}&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
When you open the curly brackets, you can’t open again until you close it. Take a look at the documentation so you can become more familiar with how to set variables and build a single string out of two of them: https://gohugo.io/templates/introduction/
1 Like
Thank you for your quick reply.
{{ $dataJ := getJSON “https://maps.googleapis.com/maps/api/place/details/json?placeid= {{ .Param “place_id” }}&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
It doen’t work.
I think that it is error in case there are multiple double quotes.
===
{{ $dataJ := getJSON ($.Param “json_url”) }}
It works when I try it with your advice.
The code is as follows.
{{ $urlPre := “https://maps.googleapis.com/maps/api/place/details/json?placeid= ” }}
{{ $urlAfter := “&fields=name,rating,formatted_phone_number&key=YOUR_API_KEY” }}
{{ $dataJ := getJSON $urlPre ($.Param “place_id”) $urlAfter }}
I didn’t follow the problem closely, but, I’m not sure that you can nest template curly brace expressions? I think that does not work:
{{ some {{ the other thing }} thing }}
(Also, it’s probably a cut-and-paste artifact but I’ll mention just in case: using “smart” quotations causes trouble. They should be straight of course, in code.)
2 Likes