zoukankan      html  css  js  c++  java
  • 三种方案避免CSS语法与Smarty冲突 简单

    转自http://developer.51cto.com/art/201009/224929.htm

    熟悉CSS的人很快就会发现Smarty和CSS的语法存在冲突,因为二者都需要使用大括号{},这里向大家简单介绍一下避免避免Smarty与CSS语法冲突的三种方法,相信你一定会感兴趣。

    本文向大家描述一下避免Smarty与CSS语法冲突的三种方法,Smarty和CSS的语法存在冲突,因为二者都需要使用大括号{}。如果简单地将CSS标记嵌入到HTML文档首部,将导致"不可识别标记"错误。

    避免Smarty与CSS语法冲突

    熟悉CSS的人很快就会发现Smarty和CSS的语法存在冲突,因为二者都需要使用大括号{}。如果简单地将CSS标记嵌入到HTML文档首部,将导致"不可识别标记"错误:

    <html> <head> <title>{$title}</title> <styletypestyletype="text/css"> p{  margin::2px  }  </style> </head> ...  

    不要担心,因为我们有3种解决方案。

    一、使用link标记从另一个文件中提取样式信息:

    <html> <head> <title>{$title}</title> <linkrellinkrel="stylesheet"type="text/css"href="default.css"/> </head> ...   

    二、使用Smarty的literal标记将样式表信息包围起来

    这些标记告诉Smarty不要解析该标记内的任何内容:
     

    <html> <head> <title>{$title}</title> {literal}  <styletypestyletype="text/css"> p{  margin::2px  }  </style> {/literal}  </head> ...  

    三、修改Smarty的默认定界符

    可以通过设置center_delimiter和center_delimiter属性来做到这一点:
     

    <?php require("Smarty.class.php");  $smarty=newSmarty;  $smarty->left_delimiter='';  $smarty->right_delimiter='';  ...  ?>  

    虽然3种解决方案都能解决问题,但其中第一种可能是最方便的,因为将CSS放在单独的文件中是一种常见的实践做法。此外,这种解决方案不需要修改Smarty的重要默认配置(定界符)。

  • 相关阅读:
    Git ignore file for Xcode projects
    How can I create a zip archive of a whole directory via terminal without hidden files?
    What is a bare git repository?
    How to tell if UIViewController's view is visible
    Adding A Shadow To UIView
    Properties
    iOS中nil,Nil,NULL之间的区别
    FMDB的简单使用
    iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
    对retain 和 assign的理解
  • 原文地址:https://www.cnblogs.com/chyong168/p/2256077.html
Copyright © 2011-2022 走看看