phphtmlsmartycookieconsent

cookie alert with smarty


I wanted to set a cookie alert in a website using smarty but this error appears:

Fatal error: Smarty error: [in inc_header.html line 47]: syntax error: unrecognized tag: window.cookieconsent.initialise({ "palette": { "popup": { "background": "#004da0" (Smarty_Compiler.class.php, line 436) in /home/khaleel/public_html/projectxy/anyn2/engine/libs/Smarty.class.php on line 1095

And I couldn't figure out why. I would be thankful if someone could help.

Thank you in advance!

Code:

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
  "background": "#004da0"
},
"button": {
  "background": "#ed821f"
}
},
"position": "bottom-right",
"content": {
"message": "rtzuioipü",
"dismiss": "OK",
"link": "More information",
"href": "http://www.xyxy.xy"
}
})});
</script>

Solution

  • In this case, you must use {literal}{/literal}.

    Smarty raise error cause cannot recognize the curly bracers in your js code.

    Read here more - https://www.smarty.net/docsv2/en/language.function.literal