javascript - If statements with jQuery variables in an x-tmpl script -
so have x-tmpl script @ bottom of page. script prints out table of rows each record in file. part of script:
<script id="template-download" type="text/x-tmpl"> <td> {% if (file.deleteurl) { %} <button class="btn btn-danger delete" data-type="{%=file.deletetype%}" data-url="{%=file.deleteurl%}"{% if (file.deletewithcredentials) { %} data-xhr-fields='{"withcredentials":true}'{% } %}> <i class="glyphicon glyphicon-trash"></i> <span>delete</span> </button> <input type="checkbox" name="delete" value="1" class="toggle"> {% } else { %} <button class="btn btn-warning cancel"> <i class="glyphicon glyphicon-ban-circle"></i> <span>cancel</span> </button> {% } %} </td> </script>
i want check if variable in url (?user=xxx) not equal text value not show delete button in script. values trying compare defined in javascript:
var phpuser = '<?php echo $tuser; ?>'; //where $tuser variable var tusername= $('#myname').text();
i have tried to following:
<script id="template-download" type="text/x-tmpl"> var phpuser = '<?php echo $tuser; ?>'; var tusername= $('#myname').text(); <td> {% if ((file.deleteurl) && (phpuser==tusername)) { %} <button class="btn btn-danger delete" data-type="{%=file.deletetype%}" data-url="{%=file.deleteurl%}"{% if (file.deletewithcredentials) { %} data-xhr-fields='{"withcredentials":true}'{% } %}> <i class="glyphicon glyphicon-trash"></i> <span>delete</span> </button> <input type="checkbox" name="delete" value="1" class="toggle"> {% } else { %} <button class="btn btn-warning cancel"> <i class="glyphicon glyphicon-ban-circle"></i> <span>cancel</span> </button> {% } %} </td> </script>
however, console comes "phpuser not defined". can give insight please? cheers.
added style hidden button, , added following if 2 variables equal eachother:
$('.deletebutton').show();
Comments
Post a Comment