for automatically loading items via the page.children i created an page.json.twig template. if i call the file directly via “http://server.com/page.json” the *.json file is parsed like it should.
if an element inside the code calls for the json file via javascript some numbers and so are added to the file uri (http://server.com/page.json?_22344234) and an error appears that this file can not be found.
what could be a solution for this? thanks very much.
how are you calling the page via javascript? Can you paste a sample of that code?
Also can you please include your code snippets in markdown backticks? or code blocks? (see the question mark in top right of the text-entry box on this forum for help).
ok this was/is the reason. the parsed json is not valid and i have no clue how to get {{ page.title }} and so on in an array to let jsonencode via twig work…
ok right now i change the indentation and it works. so the first image is pulled out of the folder, the title, the categories out of the taxonomy tags and the url of the page
—twig
[
{% for page in page.children %}
{
“image”: “{{ page.media.images|first.url }}”,
“name”: “{{ page.title }}”,
“categories”: [{% for tag in page.taxonomy.tag %}"{{ tag }}"{% if not loop.last %}, {% endif %},{% endfor %}],
“url”: “{{ page.url }}”
{% if not loop.last %}
},
{% else%}
}
{% endif %}
{% endfor %}
]
maybe this post will help other users to deal with it. thanks for your help :)