eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

WebC docs should highlight $data

Open spencerflem opened this issue 1 year ago • 3 comments

I have been confused about how to get global data in WebC components before finding this while reading the code. I don't think it's in the WebC docs yet.

spencerflem avatar Jan 09 '24 03:01 spencerflem

Could you please share how you achieved it?

valeriivolkovskyi avatar Feb 12 '24 12:02 valeriivolkovskyi

Could you please share how you achieved it?

There is a property $data that the global properties are put into, so you can use $data.myPropererty etc.

spencerflem avatar Feb 12 '24 22:02 spencerflem

<li webc:for="post of $data.collections.posts">
  <a :href="post.url" @text="post.data.title"></a>
</li>

This worked for me and might give someone else a helpful pointer when googling, although I honestly can't remember where I found $data so I'm going to credit this GitHub issue :D

manicExpressive avatar May 16 '24 21:05 manicExpressive