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

[5.x] Provide Site attribute helper #10327

Merged
merged 2 commits into from
Jun 19, 2024
Merged

[5.x] Provide Site attribute helper #10327

merged 2 commits into from
Jun 19, 2024

Conversation

ajnsn
Copy link
Contributor

@ajnsn ajnsn commented Jun 19, 2024

When using Antlers, accessing Site attributes is straightforward. For example, you can use:
{{ site:attributes:company_name }}

In Blade, the equivalent is often done like this?
{{ $site->attributes()['company_name'] }}

However, if the attribute isn't set, this will throw an "Undefined array key" exception. Using Arr::get to handle this is an option, but it adds a lot of overhead.

This pull request introduces a simple attribute helper:
{{ $site->attribute('company_name') }}

As a bonus, this helper "supports" dot notation and allows you to provide a fallback value.

@jasonvarga jasonvarga merged commit d299cb0 into statamic:5.x Jun 19, 2024
16 checks passed
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

Successfully merging this pull request may close these issues.

2 participants