mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Added docs for body-only-if
This commit is contained in:
parent
58e0ecd1cc
commit
88b000b5c4
25
README.md
25
README.md
@ -55,6 +55,7 @@ Syntax highlighting available for [Atom](https://atom.io/) by installing the [la
|
||||
- [invoke](#invoke)
|
||||
- [Structure Manipulation](#structure-manipulation)
|
||||
- [attrs](#attrs)
|
||||
- [body-only-if](#body-only-if)
|
||||
- [Comments](#comments)
|
||||
- [Helpers](#helpers)
|
||||
- [Custom Tags and Attributes](#custom-tags-and-attributes)
|
||||
@ -1019,6 +1020,30 @@ The output would then be the following:
|
||||
</div>
|
||||
```
|
||||
|
||||
### body-only-if
|
||||
|
||||
If you find that you have a wrapper element that is conditional, but whose body should always be rendered then you can use the `body-only-if` attribute to handle this use case. For example, to only render a wrapping `<a>` tag if there is a valid URL then you could do the following:
|
||||
|
||||
```html
|
||||
<a href="${data.linkUrl}" body-only-if="!data.linkUrl">
|
||||
Some body content
|
||||
</a>
|
||||
```
|
||||
|
||||
Given a value of `"http://localhost/"` for the `data.linkUrl` variable: , the output would be the following:
|
||||
|
||||
```html
|
||||
<a href="http://localhost/">
|
||||
Some body content
|
||||
</a>
|
||||
```
|
||||
|
||||
Given a value of `undefined` for the `data.linkUrl` variable: , the output would be the following:
|
||||
|
||||
```html
|
||||
Some body content
|
||||
```
|
||||
|
||||
## Comments
|
||||
|
||||
Standard HTML comments can be used to add comments to your template. The HTML comments will not show up in the rendered HTML.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user