Skip to content

Instantly share code, notes, and snippets.

@dhoko
Created February 18, 2014 14:37
Show Gist options
  • Save dhoko/9072205 to your computer and use it in GitHub Desktop.
Save dhoko/9072205 to your computer and use it in GitHub Desktop.
Lodash/underscore custom template settings with {{ }}
_.templateSettings = {
evaluate: /{{([\s\S]+?)}}/g,
interpolate: /{{=([\s\S]+?)}}/g,
escape: /{{-([\s\S]+?)}}/g
};
@dhoko
Copy link
Author

dhoko commented Feb 18, 2014

Ex :

{{ _.each(playlist, function(item, index) { }}
<h3>{{= item.name }}</h3>
    <ul class="video-list">
        {{
        var max = item.videos.length - 1;
        _.each(item.videos, function(video, i) { 
        }}
        <li class="video-item" data-video="{{= item.name }}" data-index="{{= i }}" data-max="{{= max }}">
            <figure class="video-preview">
                <img src="assets/{{= item.thumbnail }}" alt="{{= item.name }}" >
                <figcaption>{{= video.name }}</figcaption>
            </figure>
        </li>
        {{ }); }}
    </ul>
{{  }); }}

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