DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
    • can-stream
    • can-vdom
    • can-view-import
      • Pages
        • Dynamic Imports
        • Static Imports
      • Attributes
        • can-tag
        • from
        • {^value}
    • can-zone
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-view-import
  • / On this page
    • can-view-import

      module
      • npm package badge
      • Star
      • source

      <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 />
      

      Parameters

      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>
      

      Parameters

      1. MODULE_NAME {moduleName}:

        A module that this template depends on.

      Use

      A template might depend on component or helper modules. <can-import> allows you to specify these dependencies.

      Example:

      <can-import from="components/my_tabs"/>
      <can-import from="helpers/prettyDate"/>
      
      <my-tabs>
        <my-panel title="{{prettyDate start}}">...</my-panel>
        <my-panel title="{{prettyDate end}}">...</my-panel>
      </my-tabs>
      

      Currently this only works with can-view-autorender or the steal-stache plugin.

      Progressive Loading

      A template may load or conditionally load a module after the initial page load. <can-import> allows progressive loading by using an end tag.

      The first example below shows a component being loaded ad hoc. The second illustrates conditionally loading modules based on some application state.

      Example:

      <can-import from="components/home"></can-import>
      
      {{#eq location 'home'}}
      <can-import from="components/home">
       ...
      </can-import>
      {{/eq}}
      
      {{#eq location 'away'}}
      <can-import from="components/away">
        ...
      </can-import>
      {{/eq}}
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.