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

marko-layout

v2.0.2

Published

Layout taglib for marko

Downloads

327

Readme

marko-layout

This module provides the builtin layout taglib for Marko. The layout taglib provides support for separating out an HTML layout from content. A layout a just a normal Marko template with placeholders that allow for additional content to be provided by another template.

Example

Example usage of of the layout taglib is shown in the sample code below:

default-layout.marko:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><layout-placeholder name="title"/></title>
</head>
<body>
    <h1 if="data.showHeader !== false">
        <layout-placeholder name="title"/>
    </h1>
    <p>
        <layout-placeholder name="body"/>
    </p>
    <div>
        <layout-placeholder name="footer">
            Default Footer
        </layout-placeholder>
    </div>
</body>
</html>

Usage of default-layout.marko:

<layout-use template="./default-layout.marko" show-header="$true">
    <layout-put into="title">My Page</layout-put>
    <layout-put into="body">BODY CONTENT</layout-put>
</layout-use>

Defining a layout

A layout is just a standard Marko template with special <layout-placeholder> tags.

<layout-placeholder>

Supported attributes:

  • name - The name to assign to the placeholder (required)

Each <layout-placeholder> tag should be assigned a name using the name attribute.

Each placeholder can have default content that is shown if no content for the placeholder is provided by the caller. The default content (if any) should be provided as nested content as shown below:

<layout-placeholder name="footer">
    This is the default content for the "footer" placeholder. If
    no "footer" content is provided by the caller then this content will
    be rendered.
</layout-placeholder>

The user of a layout template can provide content for a placeholder using the <layout-put> tag (described later).

Using a Layout

<layout-use>

The <layout-use> tag is used to render a layout template with content being provided by the caller.

Supported attributes:

  • template - The path to the layout template or a JavaScript expression that resolves to a loaded template instance.
  • Any remaining attributes can be used to provide additional data to the layout template (described later)

Example:

<layout-use template="./default-layout.marko" show-header="$true">
    ...
</layout-use>

<layout-put>

The <layout-put> tag is used to provide layout content.

Supported attributes:

  • into (required) - The name to of the placeholder that the content should replace
  • value (optional) - The content that should be used. If not provided the layout content for the corresponding placeholder should be provided as nested content.

If nested content is provided then it will be used the content for the corresponding placeholder.

Example usage:

<layout-put into="title">My Page</layout-put>

Alternatively, the content can be provided using the value attribute as shown below:

<layout-put into="title" value="My Page"/>

Layout Data

Additional data can be provided to a layout template by the caller. Data is separate from content and be used to control how the layout renders. Layout data will be accessible as properties in the standard data variable. Any additional attributes other than the "template" attribute that are provided to the <layout-use> tag are used to pass additional data to a layout template.

The example below shows a showHeader option can be passed to a layout template to control how the header content renders:

default-layout.marko:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><layout-placeholder name="title"/></title>
</head>
<body>
    <h1 if="data.showHeader !== false">
        <layout-placeholder name="title"/>
    </h1>
    ...
</body>
</html>

Usage of default-layout.marko:

<layout-use template="./default-layout.marko" show-header="$true">
    ...
</layout-use>

NOTE: All data attributes will be de-hyphenated and converted to camel case (e.g., show-header will be accessible via the showHeader property on the data object).