I am working on a project using sinatra with haml for templates. I want to be able to append some of my haml partials using JQuery. I am hoping to add this to a js function being triggered by an event like so
....addEventListener(myWidget, 'click', function() {
$('targetDiv').append(RenderHamlTempalte('/my/file/location/');
});
or
....addEventListener(myWidget, 'click', function() {
$('targetDiv').append(RenderHamlTempalte('/my/file/location/', {options: here, options: here);
});
I have checked out a few related projects on github but really can’t find something to do this with properly.
thanks for any info
UPDATE:
here was what I ended up going with
var url = '/update&my&div/' + param;
$('.my-div').load(url);
and then in my sinatra app.rb I can just return my haml partial
get ''/update&my&div/:params' do
# do some stuff
@make_variables_happen
haml :my_partial
end
One way to do this is to use a tool like: https://github.com/uglyog/clientside-haml-js
You would have to wrap your partials in
<script type="text/haml-template" id="template_id"> YOUR PARTIAL GOES HERE </script>and append them somewhere in your html page (I usually add them at the bottom of the page). You can then reference them from JavaScript with:and then you can pass the data with:
or based on your example: