iam trying to call the nest/node api in crafter cms but it is throwing errors
1)This is my Groovy controller code
import groovy.json.JsonSlurper
def apiUrl = "http://localhost:3000/"
def json = new URL(apiUrl).text //assuming it's json
def object = new JsonSlurper().parseText(json)
templateModel.myObject
2)This is my ftl code
<#import "/templates/system/common/crafter.ftl" as crafter />
<#assign x = contentModel.name_s!"" />
<@crafter.h1>${myObject.x}<@crafter.h1 />
3)after saving the above codes iam getting this error
Is the response at http://localhost:3000/ the following URL JSON?
If not, trying to parse it is going to throw an error.
Also, in your Freemarker template you have an error here:
Since you assigned contentModel.name_s to x, this should simply be:
Assuming the response from Node is JSON, and for the sake of the example, let's say it looks like this:
Then you can use these values in your freemarker template with:
myObject is available in the template as myObject because you added it to the template in the controller.