npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

edge-fragment

v0.1.2

Published

Add ability to render fragments from Edge template engine

Downloads

25

Readme

Edge.js fragment

typescript-image npm-image license-image

This package introduces concept of template fragments described on HTMX website to Edge.js templating.

Instalation

Install and configure it in two steps.

# npm
npm i edge-fragment
node ace configure edge-fragment

Or use ace add command that combines those two steps:

node ace add edge-fragment

Usage

Library adds @fragment tag that you can use to describe fragment of template that you might want to render separately. The fragment tag in itself does not affect final result when you render the whole file.

Fragment tag takes one argument - name of the fragment:

<header>Some header</header>
@fragment("content")
My awesome content
@end
<footer>Some footer</footer>

Now you can render template fragment by appending its id at the end after #:

// Render full template
async function full({ view }: HttpContext) {
  return view.render('path/to/template', { data })
}

// Render only template fragment
async function contentOnly({ view }: HttpContext) {
  return view.render('path/to/template#content', { data })
}

Notes about fragment extraction

Please note that fragments are extracted out of the template file before the template evaluation. Because of that you can define fragment in any place of template file, including inside other tags like @each or @if:

@let(variable = 5)
@each(item in collection)
  @fragment('item-body')
    <b>{{ item.content }}</b>
  @end
  @if(item.error)
    @fragment('item-error')
      <p>Got error: {{ item.error }}</p>
      Variable is {{ variable }}
    @end
  @end
@end

There are two main things worth keeping in mind:

  • when rendering the fragment you need to supply it with data in correct format eg. view.render('path/to/template#item-body', { item })
  • there is no data passing from template to fragment, so if you use some value in the fragment you need to explicitly provide it during rendering eg. view.render('path/to/template#item-error', { item, variable })