Reputation: 6493
I'm currently using HAML in a get-serve, web-services project. It seems that something about my set up is not allowing me to use JQuery client side template logic. Specifically...
How do I conditionally render view code based on if a variable is present. In my foo.html.haml file's I'm trying to do
{{if $data}}
Show this
{{/if}}
I'm new to building apps w/ web services to forgive me if I'm not describing my problem effeciently.
Upvotes: 1
Views: 949
Reputation: 181
If I understand correctly, it sounds like you're trying to intermix some tmpl logic with the HAML that is generating that page. It is important to remember that the jQuery tmpl will be happening after all the HAML is parsed and turned into HTML.
So, if you wanted something like the following as your client side HTML:
<script id="myTmpl" type="text/x-tmpl">
{{if $error}}
<div class="error">
Error!!!
</div>
{{else}}
<div class="non-error">
Everything looks ${adjective} to me.
</div>
{{end if}}
</script>
You can use HAMl like the following (the indentation will be off):
%script#myTmpl{:type => "text/x-tmpl"}
:plain
{{if $error}}
.error Error!
:plain
{{else}}
.non-error Everything looks ${adjective} to me.
:plain
{{/if}}
Just keep in mind that you're trying to output a parseable jQuery-tmpl. Your other option is to do everything in HAML's :plain
tag, some prefer this for readability.
Upvotes: 3