各位好:
     当使用了SMARTY后,我们有时需要在程序中直接echo信息,而不是使用$smarty->assign方法来赋值了,假如我们有一个模板:index.tpl.html <html>
 .....
 <body><!--{$conshow}--></body>
 </html>复制代码
我们的程序代码是: <?php
 ...
 if(..){
     echo '<script>.....</script>';
 }else{
     $smarty->assign('conshow','内容....');
 }
 $smarty->display('index.tpl.html');
 ...
 ?>复制代码如果这样的话,解析后的页面会很不规范:程序直接echo的信息会出现在<html>之前,请问各位同仁是如何解决这种情况的??

解决方案 »

  1.   

    不太明白LZ意图  echo '<script>.....</script>'是来做什么的
      

  2.   

    echo '<script></script>'是当满足某条件时就弹出一个对话框,如:访客第*次访问本页,就弹出一个对话框。这样的话,echo输出的代码会在模板渲染代码(<html>)之前,显然不规范。
    如:
    aaa.html code<script>alert('')</script><html>...</html>
      

  3.   

    <?php
     ...
     if(..){
      $smarty->assign('flag','1');//在模板文件中判断然后输出 这样能不能符合你的要求?
     }else{
      $smarty->assign('flag','0');
      $smarty->assign('conshow','内容....');
     }
     $smarty->display('index.tpl.html');
     ...
     ?>
      

  4.   

    這樣還是太繁瑣了哦。如果把jquery dialog效果封裝到一個函數中,那豈不是每次調用該函數,都要在相應模板中寫上調用代碼了??
      

  5.   

    可以用 jquery来实现啊! $(document).ready(function(){
    alert('页面加载完毕后输出!');
    })
      

  6.   

    如果需要判断的话你可以 写在html后面<?php
     ...
     if(..){
      $smarty->assign('conshow','内容....');
     }
     $smarty->display('index.tpl.html');
     if(..){
      echo '<script>.....</script>';
     }
     ...
     ?>