Hi, I have two article containers named “Programs” and “Artist”.
Now I would like to assign the artist to the programs.
Could anyone tell me how is this possible to do?
Thanks in advance.
What exactly are these “article containers”?
If both “Programs” and “Artists” are normal MODX resources, then you could use a TV of input type “Listbox (Multi-Select)” and use a @
-binding (for example @SELECT
) for the field “Input Option Values”.
Or you could try the extra SuperBoxSelect (if there are a lot of “Artist” resources):
These are containers of “Article” Extra.
[[pdoResources?
&parents=`3`
&tpl=`program_item`
&includeTVs=`assign_artist, article_type, date_from, expire_date, articlestags, post_feature_image`
&processTVs=`1`
&where=`{
"assign_artist: LIKE ": "%[[*id]]%"
}`
]]
And this code works for display the related articles in the author page.
But now the problem is “multiselect” tv field display selected item’s id instead of value/label.
Input Assigned to : [[+tv.assign_artist]]
Output Assigned to : 35||36
Expected output Assigned to : James Jonathon, Mark Neel
You need to run pdoResources a second time to query the names of the artists.
For example if [[+tv.assign_artist]]
is 35||36
, then use the output modifier “replace” to convert the value into a comma separated list of IDs: [[+tv.assign_artist:replace=`||==,`]]
→ 35,36
.
Then use this for the " &resources" property of the pdoResources call like this (if the artist name is stored in the field “pagetitle”):
[[pdoResources?
&tpl=`@INLINE {{+pagetitle}}`
&resources=`[[+tv.assign_artist:replace=`||==,`]]`
&parents=`0`
&outputSeparator=`, `
&limit=`0`
]]
This can give you wrong results. For example if the value of [[*id]]
is 1
, if will also match values like 11
, 12
, 21
etc.
What’s the solution of this?
There are different solutions. One is to use FIND_IN_SET
instead:
[[pdoResources?
...
&includeTVs=`assign_artist, article_type, date_from, expire_date, articlestags, post_feature_image`
&where=`FIND_IN_SET([[*id]], REPLACE(assign_artist, '||', ',')) > 0`
]]
Yes, It displays the selected value(pagetitle), but how to add url to this name?
You have to change the template &tpl
.
Use &tpl=`@INLINE <a href="{{~{{+id}}}}">{{+pagetitle}}</a>`
(or [[~[[+id]]]]
in a separate chunk).
Thank you so much for your help. I genuinely appreciate the time and effort you put into assisting me. Your support has been invaluable.
@halftrainedharry
I am facing a problem with this.
When no artist is selected it shows all the artists from the list.
[[!pdoResources:!empty=`
<li>
Artist:
<span>
[[!pdoResources?
&tpl=`@CODE:<a href="{{~{{+id}}}}">{{+pagetitle}}</a>`
&resources=`[[+tv.assign_artist:replace=`||==,`]]`
&parents=`0`
&outputSeparator=`, `
]]
</span>
</li>
`?
&tpl=`@CODE:<a href="{{~{{+id}}}}">{{+pagetitle}}</a>`
&resources=`[[+tv.assign_artist:replace=`||==,`]]`
&parents=`0`
&outputSeparator=`, `
]]
You probably have to test the value of the TV, instead of the result from pdoResources.
Something like this:
[[+tv.assign_artist:!empty=`
<li>
Artist:
<span>
[[pdoResources?
&tpl=`@CODE:<a href="{{~{{+id}}}}">{{+pagetitle}}</a>`
&resources=`[[+tv.assign_artist:replace=`||==,`]]`
&parents=`0`
&outputSeparator=`, `
]]
</span>
</li>
`]]
(No need to call pdoResources uncached here!)
Thanks for your kind.
It works now.