PHP常规模板引擎中与CSS/JSON冲突的解决,cssjson
PHP常规模板引擎中与CSS/JSON冲突的解决,cssjson
主要针对对象:Smarty/Dwoo
参考:http://developer.51cto.com/art/201009/224929.htm
其实以前都不怎么关注模板引擎,觉得没必要使用。但随着年龄的增加,代码洁癖越来越严重,才开始碰到这个问题。
Smarty和CSS/JS的语法存在冲突,因为二者都需要使用大括号{}。虽然可以改Smarty的界定符,但你在一个现存系统中,去修改所有相关代码,是不划算的。
1. 避免同时出现
通过外部引用的方式避免。问题是避无所避。所以这种情况只适合少量简单的情况。
2. 修改Smarty界定符
2. 使用Smarty的literal标记将样式表信息包围起来
<span><</span><span>html</span><span>></span> <span><</span><span>head</span><span>></span> <span><</span><span>title</span><span>></span>{$title}<span></</span><span>title</span><span>></span><span> {literal} </span><span><</span><span>styletypestyletype</span><span>="text/css"</span><span>></span><span> p</span><span>{</span><span> margin</span><span>:</span><span>:2px </span><span>}</span> <span></</span><span>style</span><span>></span><span> {/literal} </span><span></</span><span>head</span><span>></span>
<span><</span><span>script </span><span>type</span><span>="text/javascript"</span><span>></span> <span>function</span><span> goods_show(id){<br /><br /></span><span><!--</span><span>{literal}</span><span>--><br /><br /></span><span>art.dialog.open(url,{id:</span><span>'</span><span>select</span><span>'</span><span>,title:</span><span>'</span><span>的:</span><span>'</span><span>,width:</span><span>760</span><span>,height:</span><span>380</span><span>,padding: </span><span>'</span><span>10px</span><span>'</span><span>});<br /><br /></span><span><!--</span><span>{</span><span>/</span><span>literal}--></span> <span> } </span><span></</span><span>script</span><span>></span>
第三种无疑是绿色环保的,在遇到冲突的地方,加上literal标记包裹。
该方案对Dwoo引擎同样有效。
关于框架你可以这么理解, 就像一个大楼的地基, 无论大楼怎么盖, 打造地基的方法永远都是类似的.
在我们进行程序开发的过程中, 你会发现每个程序之间都要有很多类似的东西和可以重用的东西, 如果你每个项目过后都把这些类似的东西积累起来, 那么这些代码可以称为库, 当库越来越强大, 甚至连程序结构都可以重用的时候, 你就可以叫他框架了.
国内比较好的框架有thinkPHP, fleaPHP, 国外zendFramework和symfony. 如果楼主想靠php找工作建议学zendFramework, 如果个人开发建议使用symfony.
关于模板引擎, 你可以理解成施工队里刷油漆的, 他们是专业刷油漆的, 盖楼的不用管油漆怎么刷, 刷油漆的也不关注楼是怎么盖的.
其实模板引擎的主要作用还是将逻辑和显示进行分离, 最初可能是为了让程序员和美工更好的进行配合, 既然初学者, 我想你经常会把php代码和html写到一起, 你自己是可以看懂的, 但是美工不一定看得懂, 他们可能只能看懂html和css, 再者说如果美工在混合代码里加了复杂的css或者js你也一样会看不懂, 这样就给程序开发带来了很大的困难. 所以才有了模板引擎, 它将逻辑和显示完全分离, 程序员只需要关注逻辑, 在程序的最后将数据准备好然后传递给模板, 而美工只要修改模板而不需要考虑程序逻辑, 模板技术在团队开发中是经常使用的, 这里推荐你学习smarty.
不知道有没有讲透, 有不懂可以补充.
echo '
im create by php '
?>
编译后,HTML结构是什么?CSS是在客户端运行,所以当你发现样式不对的时候,你查看源文件,保存为HTML去检查,看有什么不同,如果你是AJAX做的,源文件没有对应的结构,那就就打开FireBug 复制代码生成HTML 再去检查!
总之,要检查CSS,请不要盯着程序看,放到客户端HTML的环境下去测试吧!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In recent years, the template engine in PHP programming has become an important part of PHP development, making it easier for programmers to develop and manage pages. This article will introduce common template engines in PHP programming. SmartySmarty is a commonly used PHP template engine. It supports a series of functions such as cached templates, plug-in modules and custom functions. Smarty's syntax is very flexible and can solve the problem of combining PHP variables with HTML tags, making the PHP language more suitable for templated design. Moreover, S

Fat-Free Framework is a lightweight PHP framework designed to provide simple and flexible tools for building web applications. It contains many useful features such as routing, database access, caching, etc. In the Fat-Free framework, using the Blade template engine can help us manage and render templates more conveniently. Blade is the template engine in the Laravel framework, which provides powerful syntax and template inheritance capabilities. In this article I will demonstrate how to use Bl in Fat-Free framework

ThinkPHP6 template engine usage guide: Create an exquisite front-end interface Introduction: With the development of web applications, the design and development of front-end interfaces have become increasingly important. As a developer, we need to use a powerful template engine to help us create and manage front-end interfaces. ThinkPHP6's template engine is a powerful tool to meet this need. This article will introduce how to use the ThinkPHP6 template engine to create a beautiful front-end interface. Part 1: Install ThinkPHP6 template engine

Golang Template Engine Getting Started Guide: How to use templates in Golang, specific code examples are required Introduction: A template engine is a tool that can combine data and templates and generate documents in HTML, text or other formats. In Golang, we can use the built-in template package (html/template) to implement the functions of the template engine. This article will introduce in detail how to use the template engine in Golang and provide specific code examples. 1. The basic concept of template engine is to understand how to use it.

With the development of Internet technology, the demand for web applications is also increasing. Web developers often use template engines to generate dynamic web pages. This article will explore a new template engine: the Go language template engine. What is the Go language template engine? Go language is an advanced programming language developed by Google. Its syntax is concise and clear, making it easy to learn and use. The Go language template engine is a template system used to generate HTML templates in the Go language. The Go language template engine is called the "standard library".

Sharing experience on template engine selection and use in JavaScript development Introduction: In modern front-end development, the template engine (TemplateEngine) plays a crucial role. They enable developers to organize and manage large amounts of dynamic data more efficiently and effectively separate data from interface presentation. At the same time, choosing an appropriate template engine can also bring developers a better development experience and performance optimization. However, among the many JavaScript template engines, which one should you choose? catch

PHP is a language widely used in web development. Whether you are developing a small website or a large system, PHP is very popular and convenient. In the PHP development process, we need to separate the logic and data layers, which requires the use of a template engine. The template engine can be simply understood as merging data and template files to generate the final HTML file. In this article, we will introduce some of the best template engines available in PHP. SmartySmarty is one of the most popular template engines in PHP,

Nowadays, website development is inseparable from an important component-template engine. A template engine refers to a tool that combines page templates and data to generate HTML code with a specific format. In various website development frameworks, the template engine is an essential component, because the template engine can greatly reduce the duplication of code and improve the dynamics of the page. One of the most common and popular template engines is Smarty. Smarty is a DSL (DomainSpecif
