Solves the problem of smartycompilerexception caused by CSS in the smarty template.

Source: Internet
Author: User

A PHP parsing error occurs when the smarty template engine is applied in the project today. It is mainly located in the CSS section, and the error is shown as "uncaught
Exception 'smartycompilerexception' with message' syntax error in
Template ". After careful analysis, we found that HTML-embedded CSS
{} The curly braces conflict with the definition symbol {} of the smarty. If you embed the CSS Tag into the header of the HTML document, the "Unrecognized tag" error will occur, you can find three solutions to solve this problem:

1. External link CSS file.Use link external links to cascade style sheet files. For example:

 
<Link href = "style.css" type = "text/CSS" rel = "stylesheet"/>

2.
Use literal flag.
Use the literal tag unique to smarty to identify areas that do not need to be parsed. Use the region tag {literal} and {/literal} to skip the analysis and output directly, this will not cause conflicts.

 
{Literal} <style type = "text/CSS"> body {color: # fff ;}</style >{/ literal}

3.
Modify the default delimiter of smarty.
This goal is achieved by setting the left_delimiter and right_delimiter attributes.

Require ("Smarty. Class. php"); $ template = new smarty; $ template-> left_delimiter = '<{'; $ template-> right_delimiter = '}> ';

The disadvantage of the 3rd method is that you need to modify the parsing tag of the original template, which is troublesome. We recommend 1st and 2nd flexible combinations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.