CE slots should also support self-closing tags. no-end tags like "img"

Comments

pagach created an issue. See original summary.

pagach’s picture

StatusFileSize
new2.08 KB

Added new parameter to define if tag should be self-closing.

pagach’s picture

StatusFileSize
new2.38 KB

New patch that support self-closing tags and default slot name.

fago’s picture

Title: Support self-closing tags » Support self-closing tags in slots
Status: Active » Needs work

- What's the use case for the self-closing tag? Img tag? that's not self-closing but has no end tag in html5: https://www.w3schools.com/tags/tag_img.asp - that's not really self-closing, but just no end tag. We could just hard-code the list of tags which have no end-tag and render them without end-tag? Or leave it up the caller to decide?

also see e.g. https://blog.teamtreehouse.com/to-close-or-not-to-close-tags-in-html5

pagach’s picture

I'm sure there are other use cases for self closing tags, we are after all using "custom elements" so we can make some custom self-closed tag.
Img is not self-closing yes, but if made as self-closing doesn't break the frontend, if closed like it breaks frontend.

pagach’s picture

StatusFileSize
new2.39 KB

Hardcoded list of no end tags.

fago’s picture

Title: Support self-closing tags in slots » Some tags get end tags when used in slot which may not

right, so let's make this about end-tags.
For self-closing tags, I'd suggest we open another issue and just auto-improve into

fago’s picture

Issue summary: View changes

+ $this->slots[$key] = [
+ 'tag' => $tag,
+ 'content' => $value,
+ 'attributes' => new Attribute($attributes)
+ ];

That's a bit weird. Imo, if it's a no-end tag so it cannot have content. Let's not add $value here and throw a logic exception is a non-empty value is passed for a no-end tag.

pagach’s picture

Yes, but in setSlot($key, $value, $tag = 'div', $attributes = []) you need to pass a $value.
I'd leave it up to the implementation to just pass an empty string.

fago’s picture

right, but point is - it's invalid usage if something non-empty is passed. As a good API, we should tell people when they do something which will end up broken and refuse to do so. And having a non-ending tag with content is broken.

pagach’s picture

StatusFileSize
new2.74 KB

Added logic exception if no-end tag is given content.

fago’s picture

Status: Needs work » Reviewed & tested by the community

thx, that seems good now.

  • pagach committed b5fda8f on 8.x-2.x
    Issue #3054882: Fix no end tags getting end tag.
    
fago’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.