Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entries from another site can be selected in the back end, but they are not output in Twig templates. #885

Open
mike-moreau opened this issue May 1, 2024 · 2 comments
Labels
bug status: unconfirmed A bug report that has not yet been reproduced by the maintainer(s), and more information is required bug

Comments

@mike-moreau
Copy link

Bug Description

I am working on a multi-site installation with two sites.

I have a section called "Articles" that is enabled for the Primary site only, and I have a section called "Pages" that is enabled for the Secondary site only.

There is a Neo field called "Blocks" that is available on both Articles and Pages.

On the Secondary Site in the Pages section, I can add selected articles to an entries field. It works as expected in the back end. When I try to output the selection on the front end, the entries field is empty.

Screenshots of the Primary Site:

Screenshot 2024-05-01 at 10 02 16 AM Screenshot 2024-05-01 at 10 02 25 AM Screenshot 2024-05-01 at 10 03 08 AM

Screenshots of the Secondary site:
Screenshot 2024-05-01 at 10 03 23 AM

Articles from primary site can be selected.

Screenshot 2024-05-01 at 10 03 43 AM Screenshot 2024-05-01 at 10 03 50 AM

Article relations are empty in primary site

Screenshot 2024-05-01 at 10 04 01 AM

The related articles field allows for the site select menu:

Screenshot 2024-05-01 at 10 02 44 AM

The code to render the block field looks like this:

{% for block in entry.blocks.all() %}
    {% if block['relatedArticles'] is defined %}
        {% for article in block.relatedArticles.all() %}
            {{ article.title }}
        {% else %}
            No related articles.
        {% endfor %}
    {% endif %}
{% endfor %}

Steps to reproduce

  1. Configure the test content and relations
  2. Attempt to output relationship in twig from Primary site only on Secondary Site

I'm happy to provide a DB dump or other config files if it would be helpful.

Expected behaviour

The relationships to Primary site content would be output in twig.

Neo version

4.1.2

Craft CMS version

4.9.0

What is the affected Neo field's propagation method?

Save blocks to all sites the owner element is saved in.

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

@ttempleton
Copy link
Contributor

This seems to be the case for me even when putting the entries field directly on the entry's field layout - could you please confirm whether that's what happens for you?

@ttempleton ttempleton added bug status: unconfirmed A bug report that has not yet been reproduced by the maintainer(s), and more information is required and removed bug status: new labels May 13, 2024
@mike-moreau
Copy link
Author

@ttempleton yes! I see the same behavior with the entries field on the entry itself.

Checking further, if I add a site('*') parameter to the query, then the articles from the other site are retrieved.

{% for r in entry.relatedArticles.site('*').all() %}
    {{ r.title }}
{% else %}
    No related articles on the entry.
{% endfor %}

{% for block in entry.blocks.all() %}
    {% if block['relatedArticles'] is defined %}
        {% for article in block.relatedArticles.site('*').all() %}
            {{ article.title }}
        {% else %}
            No related articles.
        {% endfor %}
    {% endif %}
{% endfor %}

So what must be happening is the that the current site is used by default when no site param is specified, and we need to expressly set it to get the entries from other sites.

Looks like this is the expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status: unconfirmed A bug report that has not yet been reproduced by the maintainer(s), and more information is required bug
Projects
None yet
Development

No branches or pull requests

2 participants