Reputation: 11609
I opened a question yesterday about javascript and smarty, so since I wasn't able to deal with the { %} tags. All the info can be found here
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
{% if (file.error) { %}
<td></td>
<td class="name"><span>{%=file.name%}</span></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
{% } else { %}
<td class="preview">{% if (file.thumbnail_url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" data-gallery="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
{% } %}</td>
<td class="name">
<a href="{%=file.url%}" title="{%=file.name%}" data-gallery="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
</td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td colspan="2"></td>
{% } %}
<td class="delete">
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="icon-trash icon-white"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1">
</td>
</tr>
{% } %}
</script>
I am trying to put the tags inside strings as so :
<script id="template-download">
for (var i=0, file; file=o.files[i]; i++) {
document.write('<tr class="template-download fade">');
if (file.error) {
document.write('<td></td><td class="name"><span>**');document.write(file.name);**
...
The problem is now that the last line is read partially and doens't output in my browser, but the line I put here in bold outputs litteraly in my browser. Why is that ?
Upvotes: 1
Views: 477
Reputation: 11609
Finally,
I managed to make it go right as so :
{literal}
{{literal}%{/literal} for (var i=0, file; file=o.files[i]; i++) { {literal}%{/literal}} ...{/literal}
and so on...
Upvotes: 2