Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for partials object #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pkuras
Copy link

@pkuras pkuras commented Jun 4, 2014

jQuery Mustache plugin was missing support for partial objects which are supported by Mustache. From Mustache docs:

In mustache.js an object of partials may be passed as the third argument to Mustache.render. The object should be keyed by the name of the partial, and its value should be the partial text.

Mustache.render(template, view, {
  user: userTemplate
});

The patch adds support for such object. This allows to choose partial templates dynamically. For example, if template has partial with name {{> content}}, it is now possible to render some differently named template in place of this partial.

Here's an usage example:

        <script type="text/html" id="div">
            <div>
            Div content:
            {{> content}}
            </div>
        </script>
        <script type="text/html" id="content1">
            Hello world!
        </script>
        <script type="text/html" id="content2">
            Bye world!
        </script>
    $('body').mustache('div', {}, {}, {content: 'content1'});
    $('body').mustache('div', {}, {}, {content: 'content2'});

And the result:

Div content: Hello world!
Div content: Bye world!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant