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

Load picture srcset from partial #4

Merged
merged 7 commits into from Mar 24, 2023

Conversation

marcorieser
Copy link
Contributor

@marcorieser marcorieser commented Mar 24, 2023

Sometimes the default picture srcset definition is not ideal for a specific case or the whole project. At the moment the only solution would be to alter the picture partial by publishing it but this cuts it off from future updates in the addon.

I was wondering if it wouldn't be nice to override the default definition by publishing just the default definition, or to pass a different definition for a specific case.

Due to when / how Antlers evaluates the variables the definition has to be in a partial.

{{# Uses the default definition (no changes) #}}
{{ partial:statamic-peak-tools::components/picture ... }}

{{# Uses a custom definition by passing a path #}}
{{ partial:statamic-peak-tools::components/picture ...  srcset_from="path/to/definition" }}
{{# the definition in `path/to/definition` #}}
{{ srcset = [
   ... 
  [ 'width' => 3840, 'ratio' => '{ ratio_large ?? ratio ?? original_ratio }' ],
] }}

Changes proposed in this pull request:

  • Extract the default srcset definition to a dedicated partial
  • Adds the ability to pass a path to a partial which holds an alternative definition for the srcset variable

@marcorieser marcorieser changed the title PoC: Load srcsets from partial if provided PoC: Load picture srcsets from partial if provided Mar 24, 2023
@marcorieser
Copy link
Contributor Author

Appropriate location for the default definition has to be defined.

@marcorieser marcorieser marked this pull request as ready for review March 24, 2023 10:37
@marcorieser marcorieser changed the title PoC: Load picture srcsets from partial if provided Load picture srcsets from partial if provided Mar 24, 2023
@robdekort
Copy link
Contributor

Nice work. The snippets folder seems fine to me.

@robdekort
Copy link
Contributor

robdekort commented Mar 24, 2023

And perhaps this is a nice chance to rename srcsets to srcset (not plural).

@marcorieser marcorieser marked this pull request as draft March 24, 2023 12:17
…set` to `srcset_from` and remove folder structure in `snippets` folder
@marcorieser marcorieser changed the title Load picture srcsets from partial if provided Load picture srcset from partial if provided Mar 24, 2023
@marcorieser marcorieser changed the title Load picture srcset from partial if provided Load picture srcset from partial Mar 24, 2023
@marcorieser
Copy link
Contributor Author

Since the Maestro Koster has no better approach for overwriting the variable, I'd release it in to the wild.

@marcorieser marcorieser marked this pull request as ready for review March 24, 2023 13:33
@robdekort robdekort merged commit 52dabfe into studio1902:main Mar 24, 2023
@marcorieser marcorieser deleted the srcsets-for-picture branch March 24, 2023 13:36
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.

None yet

2 participants