Home  >  Article  >  Backend Development  >  Resolution of conflicts with CSS/JSON in PHP regular template engine, cssjson_PHP tutorial

Resolution of conflicts with CSS/JSON in PHP regular template engine, cssjson_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:20:53987browse

Resolution of conflicts with CSS/JSON in PHP regular template engine, cssjson

is mainly targeted at: Smarty/Dwoo

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

In fact, I didn’t pay much attention to template engines before and felt that there was no need to use them. But as I get older, my code obsession becomes more and more serious, and I start to encounter this problem.

There is a syntax conflict between Smarty and CSS/JS because both require the use of curly brackets {}. Although you can change Smarty's delimiter, it is not cost-effective for you to modify all related codes in an existing system.

1. Avoid simultaneous

Avoided by external references. The problem is that there is no avoiding it. So this situation is only suitable for a small number of simple situations.

2. Modify Smarty delimiter

2. Use Smarty’s literal tags to surround style sheet information

<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>

The third type is undoubtedly green and environmentally friendly. Where conflicts are encountered, add literal to mark the package.

This solution is also effective for Dwoo engine.

php framework and template engine are a thing

You can understand the framework this way, just like the foundation of a building. No matter how the building is built, the method of building the foundation will always be similar.

In the process of our program development, you will find There must be many similar things and reusable things between each program. If you accumulate these similar things after each project, then these codes can be called libraries. When the libraries become more and more powerful, they may even be When the program structure can be reused, you can call it a framework.

The better domestic frameworks include thinkPHP, fleaPHP, foreign zendFramework and symfony. If you want to find a job in PHP, I suggest you learn zendFramework. It is recommended to use symfony for development.

Regarding the template engine, you can think of it as the painters in the construction team. They are professional painters. Those who build buildings do not care how to apply paint, and those who paint do not pay attention to the shape of the building. How to build it.

In fact, the main function of the template engine is to separate logic and display. Initially, it may be to allow programmers and artists to cooperate better. Since you are a beginner, I think you often use PHP If the code and HTML are written together, you can understand it yourself, but the artist may not be able to understand it. They may only be able to understand HTML and CSS. Furthermore, if the artist adds complex CSS or JS to the mixed code, you will not be able to understand it either. You will still not be able to understand it, which brings great difficulties to program development. That’s why there is a template engine, which completely separates logic and display. Programmers only need to focus on the logic, prepare the data at the end of the program, and then Pass it to the template, and the artist only needs to modify the template without considering the program logic. Template technology is often used in team development. I recommend you to learn smarty.

I don’t know if it has been explained thoroughly. If you don’t understand, it’s ok. Supplement.

php dynamically generates html tags and CSS issues

eed1266070b33fe84d9b35f9b38cead8 im create by php 94b3e26ee717c64999d7867364b1b4a3'
?>

After compilation, what is the HTML structure? CSS is run on the client, so when you find that the style is wrong, you check the source file and save it as HTML to check and see if there is any difference. If you do it with AJAX and the source file does not have a corresponding structure, then open it FireBug copy the code to generate HTML and check it again!

In short, if you want to check CSS, please don’t stare at the program, put it in the client-side HTML environment and test it!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/864309.htmlTechArticleResolution of conflicts with CSS/JSON in PHP regular template engine, cssjson mainly targets: Smarty/Dwoo Reference: http ://developer.51cto.com/art/201009/224929.htm In fact, I didn’t pay much attention to it before...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn