Skip to content

Instantly share code, notes, and snippets.

@jcblw
Last active August 29, 2015 14:17
Show Gist options
  • Save jcblw/ad9dfdb44033195f5f7c to your computer and use it in GitHub Desktop.
Save jcblw/ad9dfdb44033195f5f7c to your computer and use it in GitHub Desktop.
Helper Ideas

Require Helper

This helper will allow you to grab from cache sets of data. This helps decouple the need to do everything inside a view and allows data to be injected into the context while inside of the template. Eg.

{{require 'models/search'}} {{!-- outputs nothing --}}

{{#with search}}
	<div class="search-container">
		<input type="search" data-lat={{lat}} data-lng={{lng}} />
		{{#each location}} ... {{/each}}
	</div>
{{/with}}

As you can see in the example we required in a model of search ( from cache ) and it exported out a variable search into the scope of the template.

It might also be cool to explore using this type of behavior ( if it works ) to create components using something like this. I dont know how exactly this would work right now but it sounds pretty cool.

{{require 'models/video-1337'}} {{!-- check instance to see if model apply to template --}}
{{require 'views/Video' exports="Video"}} {{!-- data in template applied to new view --}}

{{Video}} {{!-- video component with model video-1337 --}}

Not as configurable ad I would like but might be a cool experiment.

@jcblw
Copy link
Author

jcblw commented Mar 17, 2015

This is helper example.

{{#Video className="hello" videoId="1337"}}
  <h1>Video Title</h1>
{{/Video}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment