The examples in this article describe methods to avoid syntax conflicts between Smarty and CSS. Share it with everyone for your reference. The specific analysis is as follows:
Those who are familiar with CSS will quickly find that there is a syntax conflict between Smarty and CSS, because both require the use of curly brackets {}. Simply embedding CSS tags into the header of an HTML document will result in an "unrecognized tag" error:
<html> <head> <title>{$title}</title> <style type="text/css"> p{ margin::2px } </style> </head> ...
Don’t worry because we have 3 solutions.
1. Use the link tag to extract style information from another file:
<html> <head> <title>{$title}</title> <link rel="stylesheet" type="text/css" href="css/default.css"/> </head> ...
2. Use Smarty’s literal tag to surround style sheet information
These tags tell Smarty not to parse anything within this tag:
<html> <head> <title>{$title}</title> {literal} <style type="text/css"> p{ margin::2px } </style> {/literal} </head> ...
3. Modify Smarty’s default delimiter
This can be done by setting the center_delimiter and center_delimiter properties:
<?php require("Smarty.class.php"); $smarty=newSmarty; $smarty->left_delimiter=''; $smarty->right_delimiter=''; ... ?>
While all 3 solutions will solve the problem, the first of them is probably the most convenient since putting CSS in a separate file is a common practice. Furthermore, this solution does not require modification of Smarty's important default configuration (delimiters).
I hope this article will be helpful to everyone’s PHP programming design.