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

There is no {{ sites }} tag to loop over sites #2513

Closed
riasvdv opened this issue Sep 23, 2020 · 9 comments
Closed

There is no {{ sites }} tag to loop over sites #2513

riasvdv opened this issue Sep 23, 2020 · 9 comments

Comments

@riasvdv
Copy link
Contributor

riasvdv commented Sep 23, 2020

Bug Description

A {{ sites }} tag does not exist.

@eldor
Copy link

eldor commented Sep 23, 2020

Agree with @riasvdv we need the {{ sites }}available in antlers templates to switch between multiple sites.

@riasvdv
Copy link
Contributor Author

riasvdv commented Sep 23, 2020

{{ locales }} seems to return sites data, but only the sites that the current entry is available & published in. There should be a way to get all sites

@jasonvarga
Copy link
Member

A bit ugly, but you can do this:

{{ foreach:config:statamic:sites:sites as="handle|site" }}
    {{ handle }} {{ site:name }} {{ site:locale }} {{ site:url }} <br>
{{ /foreach:config:statamic:sites:sites }}
<?php
return [
    'sites' => [
        'default' => [
            'name' => 'English',
            'locale' => 'en_US',
            'url' => '/',
        ],
        'french' => [
            'name' => 'French',
            'locale' => 'fr_FR',
            'url' => '/french/',
        ],
    ]
],
english English en_US /
french French fr_FR /french/

@eldor
Copy link

eldor commented Sep 24, 2020

Hi @jasonvarga, yes that is working, but as you wrote your self, its a but ugly, but will do for now.

@robdekort
Copy link
Contributor

robdekort commented Oct 8, 2020

Tampering with this. With that workaround you can't get the localised url for the current entry if it's there right?

@robdekort
Copy link
Contributor

robdekort commented Oct 8, 2020

Haha ok. I've got two locales on this site. So I always want to show a link to the localised url for the current entry. If the entry is not localised the {{ locales }} wouldn't show anything and I do need to signal the visitor that there are localised pages. It's horrible but I settled for this if anyone needs it:

{{ locales }}
    {{ unless locale.key == current }}
        <li>
            <a href="{{ url }}">{{ locale.key }}</a>
        </li>
    {{ /unless }}
    {{ if total_results == 1 }}
        {{ foreach:config:statamic:sites:sites as="handle|site" }}
            {{ unless locale.key == handle }}
                <li>
                    <a href="{{ site:url }}">{{ handle }}</a>
                </li>
            {{ /unless }}
        {{ /foreach:config:statamic:sites:sites }}
    {{ /if }}
{{ /locales }}

@robdekort
Copy link
Contributor

Oh nice Jason 👍

@verybigelephants
Copy link

can we get some docs on this?
i just found this when dealing with this problem by accident and there is no entry "sites" in the documentation https://statamic.dev/tags/sites

@jasonvarga
Copy link
Member

Docs: https://statamic.dev/variables/sites

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.

5 participants