11ty / 11ty/webc

Order of operations: slot content with WebC Transforms

Open
#103 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

education
Dominant language
JavaScript
Stars
1.4k
Forks
46
Avg merge
10m
Merged PRs (30d)
2

Description

So imagine a webc component named reverse. The idea is to take content from the default slot and reverse it. It would be used like so:

<reverse>
This is a test.
</reverse>

And the output would simply reverse that string. I tried doing this with Liquid, like so:

<template webc:type="11ty" 11ty:type="liquid">

  {% capture content %}
  <slot><p>Im the default slot.</p></slot>
  {% endcapture %}

  <p>
  Content: {{ content }}
  </p>

  <p>
  Content reversed: {{ content | split: "" | reverse | join: "" }}
  </p>
</template>

The output was... unusual:

Content: This is a test.

Im the default slot.

Content reversed: >tols/<>p/<.tols tluafed eht mI>p<>tols<

It correctly captured the default slot, but then output the default text as if I had not passed any in. And then - oddly - despite the content variable being correct, when the split/reverse/join is called, it used the raw HTML.

You can see this here:

https://glitch.com/edit/#!/determined-honorable-porch?path=src%2F_includes%2F_components%2Freverse.webc%3A18%3A0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior in the linked Glitch example, starting with src/_includes/components/reverse.webc around line 18 and its Liquid template. Compare the captured default-slot value with the value passed through split, reverse, and join. Done means the slot is not emitted unexpectedly and the reverse operation uses the intended captured content.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.