Beneath each article (single entry page) I would like to show related articles.
I have four slots. For each slot I need
- the article´s title => title field
- the permalink => url_title field
- the first image => Matrix field, contains only one row.
Editors choose the related articles manually via a relationships-field. If they choose less than 4 articles, the remaining slots will be filled automatically with articles from the same category.
I use Stash to gather the list.
My problem: How do I get the image? Title and permalink are no problem, but in order to get to the image, I need to go one level "deeper" and loop through the Matrix field since my image is just a subfield of the Matrix field.
This is my code the relationship field is named thematisch_passend (german for related)
{!-- ============================================
STORE A LIST OF RELATED ARTICLES INTO A LIST
================================================== --}
{!-- first the manually chosen ones --}
{exp:stash:set_list name="rels" parse_tags="yes" trim="yes" parse_depth="2"}
{exp:channel:entries channel="artikel"}
{thematisch_passend status="not closed"}
{stash:the-title}{thematisch_passend:title}{/stash:the-title}
{stash:the-url-title-path}{thematisch_passend:url_title_path='artikel/index'}{/stash:the-url-title-path}
{exp:stash:set_list:nested name="related_entries context={entry_id}" parse_tags="yes"}
{intro_bild} <!-- name of the matrix-field -->
{stash:the-image}{ib_file}{/stash:the-image} <!-- stashes the correct image URL -->
{/intro_bild}
{/exp:stash:set_list:nested}
{/thematisch_passend}
{/exp:channel:entries}
{/exp:stash:set_list}
Next I append the automatically chosen ones to the same list. I cut the code here, because the rest works.
Here´s what Debug shows
Stash: SET related_entries context=19 to value the-image|=|http://www.mysite.de/myimage.jpg
This means, that the-image has the correct value. But when Stash builds the final list, this value somehow got lost.
Stash build this list (the first ist manually and the second one automatically selected):
SET rels to value
the-title|=|Testartikel 1|&|the-url-title-path|=|http://www.mysite.de/artikel/testartikel1|
+|the-title|=|Testartikel2|&|the-url-title-path|=|http://www.mysite.de/artikel/testartikel2|&|the-image|=|http://www.mysite.de/testartikel2_image.png
The 2nd block has an image, the first not. How can I tell stash to include the-image
in this list. Stash has already stored the correct URL.