Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use includes/partials in Rails 3 Backbone ejs.jst files
    primarykey
    data
    text
    <p>I'm using the backbone-on-rails gem with javascript (as opposed to coffeescript) to render views for a model. Everything works fine, but my view code is kind of long so I'd like to refactor things out to use includes/partials.</p> <p>Heres' my code:</p> <p>in my views/model_show.js file</p> <pre><code>AppName.Views.ModelNameShow = Backbone.View.extend({ template: JST['main'], initialize: function() { this.render(); }, render: function() { this.model.fetch({async:false}); $(this.el).html(this.template({ model: this.model })) $('#main_content').html(this.el); } }); </code></pre> <p>in my templates file I'd like to so something like this in templates/main.jst.ejs</p> <pre><code>&lt;% if(this.model) { %&gt; &lt;h2&gt; model found&lt;/h2&gt; &lt;%- include top_section %&gt; &lt;%- include middle_section %&gt; &lt;%- include bottom_section %&gt; &lt;% } else { %&gt; &lt;h3&gt;Claim not found &lt;a href='#'&gt;Back&lt;/a&gt;&lt;/h3&gt; &lt;% } %&gt; </code></pre> <p>where top_section would be a file under templates (like templates/top_section.jst.ejs)</p> <p>Problem is I keep getting the following errors (firebug output). </p> <blockquote> <p>SyntaxError: missing ) in parenthetical [Break On This Error] </p> <p>...2> model found \n\t',(''+ include top_section ).replace(/&amp;/g, '&amp;').replace(/ </blockquote> <p>which causes this error because the template isn't rendered</p> <pre><code>TypeError: this.template is not a function [Break On This Error] $(this.el).html(this.template({ model: this.model })) </code></pre> <p>I should mention that I've tried a few different syntaxes like the ones below, but those just throw different errors.</p> <pre><code>&lt;%= include top_section %&gt; &lt;%- include(top_section) %&gt; </code></pre> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload