Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I haven't tried this, but this just occurred to me as a possible solution:</p> <p>In your view create a hidden div which contains an example template (I'm using HAML here for brevity):</p> <pre><code>#tweet-prototype{:style =&gt; "display:none"} = render :partial =&gt; Tweet.prototype </code></pre> <p>Your tweet partial can render a tweet as you do now.</p> <pre><code>.tweet .tweeter = tweet.username .status = tweet.status </code></pre> <p>When creating a tweet prototype you set the fields you want to the js-template replacement syntax, you could definitely dry this up, but I'm including it here in full for example purposes.</p> <pre><code># tweet.rb def self.prototype Tweet.new{:username =&gt; "${tweet.username}", :status =&gt; "${tweet.status}"} end </code></pre> <p>On the client you'd do something like:</p> <pre><code>var template = new Template($('#tweet-prototype').html()); template.evaluate(.. your tweet json..); </code></pre> <p>The last part will be dependent on how you're doing your templating, but it'd be something like that.</p> <p>As previously stated, I haven't tried this technique, and it's not going to let you do stuff like loops or conditional formatting directly in the template, but you can get around that with some creativity I'm sure.</p> <p>This isn't that far off what you're looking to do using Isotope, and in a lot of ways is inferior, but it's definitely a simpler solution. Personally I like haml, and try to write as much of my mark up in that as possible, so this would be a better solution for me personally.</p> <p>I hope this helps!</p>
 

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