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

locales and locales:count does not work with Fluent Tags #11247

Closed
isaackearl opened this issue Dec 11, 2024 · 3 comments
Closed

locales and locales:count does not work with Fluent Tags #11247

isaackearl opened this issue Dec 11, 2024 · 3 comments

Comments

@isaackearl
Copy link

Bug description

In my project, I had localizations for english and spanish. I attempted to use the locales:count to get the number of localizations on a given page. In blade, I could not get any of the methods working for getting the count or the locales other then using this method: <s:locales:count />

I ran the example in the docs:
`{{-- Using Antlers Blade Components --}}
<s:locales:count />
<s:locales:count self="false" />

{{-- Using Fluent Tags --}}
{{ Statamic::tag('locales:count') }}
{{ Statamic::tag('locales:count')->self(false) }}`

returns
2
1

and then for the fluent tags
0
0

other methods such as @tags('locales'), does not seem to work either.

In the end I had to use @antlers @endantlers in order to get the functionality I needed.

How to reproduce

Setup a multisite page with a blade template. Test this:

I ran the example in the docs:
`{{-- Using Antlers Blade Components --}}
<s:locales:count />
<s:locales:count self="false" />

{{-- Using Fluent Tags --}}
{{ Statamic::tag('locales:count') }}
{{ Statamic::tag('locales:count')->self(false) }}`

notice that the FluentTags always just return 0. also if you do 'locales' it will always be an empty result when fetching.

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.35.0
PHP Version: 8.3.14
Composer Version: 2.8.3
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Livewire
Livewire: v3.5.17

Statamic
Addons: 2
Sites: 2 (English, Español)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.42.0 PRO

Statamic Addons
aerni/livewire-forms: 9.4.1
jonassiewertsen/statamic-livewire: 3.8.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@jasonvarga
Copy link
Member

That tag relies on context in order to figure out what entry/page ID you're targeting.

By default Blade doesn't get the context. The Antlers components do.

You can tell it which ID you mean using the id parameter (available as a fluent method). You probably have $id at that point in your template.

{{ Statamic::tag('locales:count')->id($id) }}

I'd suggest just using the Antlers component syntax though.

@isaackearl
Copy link
Author

Ok that works. My suggestion/hope is that this would be added to the documentation for locale and locale:count, or maybe as a note for FluentTags somewhere. I did a search for any mention of this in locale, locale:count, blade documentation, and the Fluent Tag docs and didn't find any mention. I spent about 3 hours on trying to find a solution before just using @antlers tags, which worked just find in the blade template other then my IDE hates it haha.

using the fluent tag is useful for things like assigning the count to the variable or doing other manipulations in blade.

Also.. is there a way to make the @tags() markup work? maybe there should be a note for that documentation as well signifying that it won't work with all the tags.

I found 3 other threads on the discord community where people were asking about this and seeking a fix, but nobody responded. I'm going to go respond to those threads now.

Thanks for helping me find the solution!

@jasonvarga
Copy link
Member

We can definitely make that clearer in the docs, thanks. I've made a note here to do that in here: statamic/docs#1573

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

No branches or pull requests

2 participants