Closed distantnative closed 4 years ago
@tobiasfabian I love this idea!
This would mean that we need to load the blueprint when rendering a page. Usually we don’t do that.
Alternatively the blueprint settings could only have the effect that the right srcset attributes get entered when using the textareas toolbar.
This is cool, I just thought about tinkering with the (image: ) kirbytag in a similar way. To keep simple I thought about using srcset preset names defined in config.php image -> thumbs -> srcset … (which I have there defined anyway) and then using the image->srcset() function in the tag's php section. :)
Theoretically:
srcset
. That includes all images placed in Textareas and Kirbytags.srcset
is an attribute of the <img>
html tag, so it should also be an (optional) attribute of the corresponding Kirbytag, just like alt
, title
or class
:
(image: 1.jpg srcset: 400, 800, 1200) // list of pixel sizes
(image: 1.jpg srcset: medium) // preset name
That means, additionally to the Srcset option in the Kirbytag, there should be a way to define default values of Kirbytags. Where would be a good place to do that?
kirbytags()
and kirbytext()
like:
// in template or snippet
$page->myField()->kirbytext([
'image' => [
'srcset' => [400, 800, 1200]
]
]);
// site/tags/image.yaml
attributes:
srcset:
- 400
- 800
- 1600
// site/config/config.php
return [
'kirbytext' => [
'img' => [
'title' => 'An image with srcset',
'srcset' => [ 400, 800, 1600 ]
]
]
];
PS: Sorry, but personally I am very emotional about this, since Wordpress so heavily messed up the separation of editing content and rendering layouts.
I fully agree with @moritzebeling : this should be invisible for editors if possible. A set of opinionated defaults, set in the config.php
would also be the first place where I'ld look to set this (consistent ith video options).
It would be a plus to expose this in the kirbytag as described above by @tobiasfabian for the more advanced editor.
If you want this to be configurable per template, but don't want to read blueprints on read content, you could also add this to config.php
e.g. like this:
// site/config/config.php
return [
'kirbytext' => [
'img' => [
'default' => [
'srcset' => [ 400, 800, 1600 ]
],
'template-a' => [
'srcset' => [ 200, 400, 800 ]
],
'template-b' => [
'srcset' => [ 300, 600, 900 ]
]
]
]
];
Who's problem are we trying to solve here? It's not like it's currently impossible or even hard to create a responsive website with Kirby. Based on a visual design you can choose if you need to implement only some automatic resolution switching or need to also bother editors with solving art direction problems. If it's not clear what built-in srcset support is supposed to solve we probably just end up with an opinionated default that ticks some responsive checkbox without much additional value over a less complex solution.
So, maybe it makes sense to formulate this feature as a User Story: As a < type of user >, I want < some goal > so that < some reason >?
Since this doesn't seem as clear cut and with our ambition to reduce issues in this repo to mainly bug reports, I have created a Idea on Nolt referencing this great discussion: https://kirby.nolt.io/112
I think you are planning something like this:
(image: plant.jpg srcset: aside)
or(image: plant.jpg srcset: 300, 800, 1024])
Which will be super cool!
Maybe it’s difficult to explain content editors the meaning of srcset. What do you think about a
srcset
field property like this.So the content editor can just throw in images and all images will be automatically resized with the given srcset.
Another idea would be srcset presets per textarea field. Like this:
But maybe that’s too much.