Skip to content
This repository has been archived by the owner on Dec 5, 2018. It is now read-only.

Custom attribute for Marko to more easily render nested body content

License

Notifications You must be signed in to change notification settings

marko-js-archive/marko-tag-body

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

marko-tag-body

Installation

npm install marko-tag-body --save

Usage

<div>
    <h1>Hello World</h1>
    <p tag-body=(data.renderBody || data.body)>
    </p>
</div>
template.renderToString({
        body: 'My body content'
    });

Output:

<div>
    <h1>Hello World</h1>
    <p>
        My body content
    </p>
</div>

A renderBody() function is passed as part of the input to the template:

template.renderToString({
        renderBody: function(out) {
            out.write('My body content')
        }
    });

Then the output would be the following:

<div>
    <h1>Hello World</h1>
    <p>
        My body content
    </p>
</div>

If the value of the tag-body is left blank then it will default to data.renderBody:

<div>
    <h1>Hello World</h1>
    <p tag-body>
    </p>
</div>
template.renderToString({
        renderBody: function(out) {
            out.write('My body content')
        }
    });

Output:

<div>
    <h1>Hello World</h1>
    <p>
        My body content
    </p>
</div>

About

Custom attribute for Marko to more easily render nested body content

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •