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

Localize Entities in Antlers by default? - Multi-Site #2991

Closed
jwahdatehagh opened this issue Sep 8, 2020 · 4 comments
Closed

Localize Entities in Antlers by default? - Multi-Site #2991

jwahdatehagh opened this issue Sep 8, 2020 · 4 comments

Comments

@jwahdatehagh
Copy link
Contributor

What i have:

  • Two sites: en and de.
  • Two Entities - let's call them Parent and Child
  • In the childs' blueprint an "Entry" Fieldtype points to a Parent. The field is not marked as "localizable" so that editors don't have to re-link entries in every language (which imho wouldn't make sense).
  • There are translations for both a Parent entity and a Child entity; The latter points to the parent (by choosing the relationship in the

The problem:
If i do the following in the template for a single parent it always shows me the default (en) version of the content, as that is what the parent ID links to.

<p>Parent: <a href="{{ parent:url }}">{{ parent:title }}</a></p>

But if i e.g. do the following, all the entries resolve to the ones in the current locale/site.

{{ collection:parents }}
    <li><a href="{{ url }}">{{ title }}</a></li>
{{ /collection:parents }}

I can't find a reasonable solution to this and would suggest to always resolve entity fields to the version in the current locale (if that exists), like the collection tag does...

@jwahdatehagh
Copy link
Contributor Author

jwahdatehagh commented Sep 9, 2020

I solved this with a custom Tag now:

use Statamic\Facades\Site;
use Statamic\Tags\Tags;

class Load extends Tags
{
    public function wildcard($tag)
    {
        $item = $this->context->value($tag);

        // Return the relation in the current locale
        return $item->in(Site::current()->handle());
    }
}

In an antlers template this looks like this:

{{ load:parent }}
    <p>Parent: <a href="{{ url }}">{{ title }}</a></p>
{{ /load:parent }}

I think this is nice for multisites... May i create a PR for this either as the default behaviour or as an additional tag?

@jasonvarga
Copy link
Member

It sounds like you're just asking the parent tag to be locale aware. I'd say it probably should do that anyway so we can consider this a bug.

@jasonvarga jasonvarga transferred this issue from statamic/ideas Dec 10, 2020
@jasonvarga jasonvarga changed the title Localize Entities in Antlers by default? - Multi-Site The parent tag doesn't localize Dec 10, 2020
@github-actions
Copy link

github-actions bot commented Feb 9, 2021

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

@github-actions github-actions bot added the stale label Feb 9, 2021
@jasonvarga jasonvarga removed the stale label Feb 15, 2021
daiwai added a commit to daiwai/cms that referenced this issue Sep 21, 2021
Fetch the parent data from the current site/locale. Fixes statamic#2991
@jasonvarga jasonvarga changed the title The parent tag doesn't localize Localize Entities in Antlers by default? - Multi-Site Sep 23, 2021
@jasonvarga
Copy link
Member

This is happening because your relationship field is called parent, which is a reserved word because it has its own special functionality associated to it.

If you rename it to parents or parent_entry it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants