Hiding an error message div with setTimeout not working using Smarty
I'm trying to hide an error message div using a javascript function setTimeout after a specified time but it gives me errors that its a wrong smarty syntax, i've never used smarty before so i would really appreciate it if anyone can help me get up to speed with this syntax
My code is as follows
{if $error_message != ""} <script type="text/javascript"> setTimeout(function(){$('error').hide(); }, 1000); </script> <div id="error" class='error_message'> 开发者_StackOverflow{$error_message} </div> {/if}
Thanks in advance
You will need to make use of literal
tag of smarty for javascript. It tells smarty compiler not to execute the code and keep as it is.
http://www.smarty.net/docsv2/en/language.function.literal
for your scenerio, try,
{literal}
<script type="text/javascript">
setTimeout(function(){$('error').hide(); }, 1000);
</script>
{/literal}
If you want to use Smarty reserved characters such as { and } elsewhere in the template like with inline JS, you have to use the literal-tag to escape it. Also, if you have some whitespace around it smarty realises it is not a smarty tag and ignores it.
See http://www.smarty.net/docs/en/language.function.literal.tpl
精彩评论