Skip to content

Commit

Permalink
update custom tags doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mlrawlings committed Jan 24, 2017
1 parent de157dd commit bce3836
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/05-custom-tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Custom tags

Marko gives you access to the same API that is used to write the [Core Tags]() so that you can extend the language with custom tags and attributes.

> **PROTIP:** We recommend that custom tags and custom attributes have at least one dash to indicate that they are not part of the standard HTML grammar.
## Writing custom tags

To get started let's look at template-based tags which allow you to include another template using a named custom tag rather than specifying a filesystem path and using `<include>`.

### Discovering tags

When compiling a template Marko will search starting at template's directory, up to the project root for directories named `components/`. It then attempts to load the children of these directories as custom tags. The children can be a Marko template or a directory with an `index.marko` template (and other supporting files).

```dir
components/
app-header/
index.marko
logo.png
style.css
app-footer.marko
pages/
home/
components/
home-banner.marko
index.marko
```

When compiling the template at `pages/home/index.marko`, the following tags would be found:

- `<app-header>`
- `<app-footer>`
- `<home-banner>`

So now, instead of needing to specify a path:

```xml
<include('../../components/app-header/index.marko')/>
```

You can just use the tag name:
```xml
<app-header/>
```

See [Advanced Tag Discovery Docs]() for more details on how to customize tag discovery.

## Exporting tags

## Using tags from npm

Using custom tags from `npm` is easy. Ensure that the package is installed and listed in your `package.json` dependencies:

```
npm install --save some-third-party-package
```

And that's it. Marko will now discover these tags when compiling your templates and you can simply use them in your templates:

```xml
<div>
<some-third-party-tag/>
</div>
```

0 comments on commit bce3836

Please sign in to comment.