I'm aware of some posts already dealing with the same topic.
Following are the links:
Javascript Template Engine Use with jQuery
I'm trying to incorporate a php explode function into a javascript template. The plugin is jQuery-File-Upload from blueimp @ https://github.com/blueimp/jQuery-File-Upload/downloads i downloaded off GitHub.
Following is part of my code i'm trying to execute and make it work.
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr>
<td>
<?php echo "{%=file.name%}"; ?> //{%file.name%} contains a string seperated by underscores
<?php $file_name_long = '{%=file.name%}'; ?>
<?php $file_name = explode ('_' , $file_name_long); ?>
<?php print_r($file_name); ?>
</td>
</tr>
...
...
I'm able to make $file_name print out as an array but I'm not able to get it seperated by the underscore within my file.name. the printed array contains the whole string as per file.name.
I'm not sure if this is even possible. I've been trying all day. If this is not do-able or logically incorrect, do let me know so that i can stop trying to want to make this work. Thanks and appreciated.
your are trying to read javascript values in your php code.
{%=file.name%}
is simply a string to php and contains no actual filenames when your php renders the output. so your print_r() would output {%=file.name%}
which then gets translated into your filename later in the browser after the whole php processing is done.
try implementing this stuff in javascript alone.
You're trying to execute server-side code (php) on the client (in your js template). The code {%=file.name%}
hasn't been replaced at the time that your php code is trying to execute it (because that's on the server).
If you mix server-side and client-side code, you really need to manage your logic to account for the server executing before the client.