Import dependencies in CanJS views
JavaScript HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
test
.editorconfig
.gitignore
.jshintrc
.npmignore
.travis.yml
build.js
can-view-import.js
can-view-import_test.js
package.json
readme.md

readme.md

can-view-import

Build Status

Import dependencies in Stache views.

API

can-view-import function

<can-import from="MODULE_NAME" />

Statically import a module from with a [can-stache] template. MODULE_NAME will be imported before the template renders.

<can-import from="components/tabs" />
<tabs-widget />
  1. MODULE_NAME {moduleName}: A module that this template depends on.

<can-import from="MODULE_NAME">content</can-import>

Dynamically import a module. MODULE_NAME will be imported dynamically; the scope within the template is a Promise.

<can-import from="components/tabs">
    {{#if isResolved}}
        <tabs-widget />
    {{/if}}
</can-import>
  1. MODULE_NAME {moduleName}: A module that this template depends on.

from="MODULE_NAME"

Passes MODULE_NAME to [can-util/js/import/import] and sets the 's viewModel to be the returned Promise.

<can-import from="bootstrap/bootstrap.css" />
  1. MODULE_NAME {String}: The name of the module to import.

can-tag="TAG_NAME"

Instantiates the provided [can-view-callbacks.tag] and sets its [can-component::viewModel viewModel] to be the Promise for the import.

  1. TAG_NAME {String}: The tag name (usually a [can-component]) to use.

{^value}="*NAME"

Sets up a [can-stache-bindings.toParent] binding to *NAME in the references scope.

  1. NAME {String}: The variable name to assign to the references scope. This can be any string name you want to use, but must be preceded by * or it will be placed on the template's View Model.

    <can-import from="app/person" {^value}="*person" />
    
    <section>
      hello {{*person.name}}
    </section>

Contributing

Making a Build

To make a build of the distributables into dist/ in the cloned repository run

npm install
node build

Running the tests

Tests can run in the browser by opening a webserver and visiting the test.html page. Automated tests that run the tests from the command line in Firefox can be run with

npm test