Last active
March 12, 2020 18:45
-
-
Save clarknelson/67b08e99e858580477ba8da0ae304d99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some notes here~ | |
{% if relatedArticlesSelect | length == 3 %} | |
{% set relatedArticles = entry.relatedArticlesSelect.limit(3).all() %} | |
is the same as | |
{% set relatedArticlesSelect = entry.relatedArticlesSelect.all() %} | |
if you know there are only going to be three elements. dot all will fetch all of the elements attached | |
This is how I would code it ~ | |
{% set selectedEntries = entry.relatedArticlesSelect %} | |
{% set existingEntries = ['not']|merge(selectedEntries.ids()) %} | |
{% set relatedEntries = craft.entries.section('articles').relatedTo(mainCategory).id(existingEntries).limit(3 - selectedEntries|length).all() %} | |
{% set allEntries = selectedEntries | merge(relatedEntries) %} | |
I believe that the sort order is post date desc by default, it might be asc. | |
This will hide elements that have already been output | |
This also assumes that the selected entries field is limited to three entries | |
Let me know if you have questions |
Thanks, i've added an allEntries
variable so it is more clear :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@clarknelson
In your example if there are 3 selectedEntries it will never output anything. There still needs to be a merge of the selectedEntries en relatedEntries. Just to let you know if you want to ever update this gist! :)