没有Smarty的错误?

时间:2018-05-03 14:06:53

标签: javascript css smarty

我得到的错误基本上不在这里,或者我是超级盲人,因为我已经花了最后30分钟。

<b>Fatal error</b>:  Uncaught  --&gt; Smarty Compiler: Syntax error in template &quot;file:C:\htdocs\smarty\templates\shopify_apps\bundle\js_modules\product_reviews.tpl&quot;  on line 30 &quot;$('head').append('&lt;style&gt; .ratings {position: relative !important;vertical-align: middle!important;display: inline-block!important;color: #b1b1b1!important; overflow: hidden!important;}.full-stars {position: absolute;left: 0;top: 0; white-space: nowrap;overflow: hidden; color: #fde16d;} .empty-stars:before, .full-stars:before {content:&quot;\2605\2605\2605\2605\2605&quot;; font-size: 14pt;}.empty-stars:before {-webkit-text-stroke: 1px #848484;}.full-stars:before {-webkit-text-stroke: 1px orange;} @-moz-document url-prefix() {.full-stars {color: #ECBE24;}}&lt;/style&gt;');&quot;  - Unexpected &quot;: &quot;, expected one of: &quot;}&quot; &lt;-- 
  thrown in <b>C:\htdocs\vendor\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php</b> on line <b>30</b><br />

这是导致它的原因

if ($('h1').length) {
  $('h1').after('<span>' + message[1] + '<div class="ratings"><div class="empty-stars"><div class="full-stars" style="width=(avgStars*20)%"></div></div></div></span>');
  $('head').append('<style> .ratings {position: relative !important;vertical-align: middle!important;display: inline-block!important;color: #b1b1b1!important; overflow: hidden!important;}.full-stars {position: absolute;left: 0;top: 0; white-space: nowrap;overflow: hidden; color: #fde16d;}   .empty-stars:before, .full-stars:before {content:"\2605\2605\2605\2605\2605"; font-size: 14pt;}.empty-stars:before {-webkit-text-stroke: 1px #848484;}.full-stars:before {-webkit-text-stroke: 1px orange;} @-moz-document url-prefix() {.full-stars {color: #ECBE24;}}</style>');
}

任何想法?

1 个答案:

答案 0 :(得分:2)

如果您的JS代码位于Smarty模板文件中,则必须将其包装在{literal}标记中。您的代码应为:

{literal}
    if ($('h1').length) {
        $('h1').after('<span>' + message[1] + '<div class="ratings"><div class="empty-stars"><div class="full-stars" style="width=(avgStars*20)%"></div></div></div></span>');
        $('head').append('<style> .ratings {position: relative !important;vertical-align: middle!important;display: inline-block!important;color: #b1b1b1!important; overflow: hidden!important;}.full-stars {position: absolute;left: 0;top: 0; white-space: nowrap;overflow: hidden; color: #fde16d;}   .empty-stars:before, .full-stars:before {content:"\2605\2605\2605\2605\2605"; font-size: 14pt;}.empty-stars:before {-webkit-text-stroke: 1px #848484;}.full-stars:before {-webkit-text-stroke: 1px orange;} @-moz-document url-prefix() {.full-stars {color: #ECBE24;}}</style>');
    }
{/literal}

应该可以。如果没有,请在您的问题中输入Smarty模板文件的完整代码,我可能会帮助您。