tideg
June 20, 2019, 11:05am
1
Hi,
I´m trying to query values from a nested structure-field into a multiselect-field like this:
Source with nested structure-field:
filterCategories:
label: Filter-Kategorien
type: structure
fields:
filterCategory:
label: Filter-Kategorie
type: text
filterTags:
label: Filter-Tags
type: structure
fields:
filterTag:
label: Filter-Tag
type: text
My multiselect-field with the query:
projectTags:
label: Tags
type: multiselect
options: query
query:
fetch: site.page(site.index.template('projektdatenbank')).filterCategories.toStructure
text: "{{ structureItem.filterCategory }}"
value: "{{ structureItem.filterCategory }}"
This works and shows the filterCategories as expected, but I´d like to go deeper and query the filterTags (nested structure-field). I´m very grateful for any help, since I´m totally stuck on this one.
I think you can’t do this with a simple query. You could create a json encoded array you provide through a route.
tideg
June 20, 2019, 11:56am
3
What a pity, but thanks for the suggestion @texnixe . I´ll try that.
tideg
June 21, 2019, 1:38pm
4
The route-solution works like a charm and has by the way other advantages in a multilanguage setup in this context.
1 Like
yatil
July 3, 2019, 1:15pm
5
Ah, this would be exactly what I need. @tideg Do you have a pointer on how to approach the route solution? (I haven’t used routes yet.)
tideg
July 5, 2019, 4:38pm
6
Sure @yatil . Based on my examples in the first post, I first built the route, which generates a JSON-File containing my wanted tags like this:
'pattern' => 'project-filter-tags.json',
'action' => function () {
$tags = array();
foreach (site()->visit(site()->index()-> ... ->toString(), 'de')->filterCategories()->toStructure() as $filterCategory) {
foreach ($filterCategory->filterTags()->toStructure() as $filterTag) {
$tagGerman = $filterTag->filterTagGerman()->toString();
$tagEnglish = $filterTag->filterTagEnglish()->toString();
$tags[$tagEnglish] = $tagGerman;
}
}
return response::json($tags);
}
Then I changed my multiselect-field in the blueprint to query this JSON-file like this:
projectTags:
label: Tags
type: multiselect
translate: false
options: api
api:
url: "{{ site.url('de') }}/project-filter-tags.json"
text: "{{ item }}"
value: '"{{ item.key }}":"{{ item }}"'
I have a two-language-setup (de/en), which makes the whole thing a little special. As you probably see, I force the editor to input both language-versions of the tags in the german panel-version. Therefore I locked the source-structure-field and the target multiselect-field in the english panel-version.
1 Like
yatil
July 6, 2019, 8:12am
7
@tideg Thank you very much, this is very helpful!