我收到的错误基本上不在这里,或者我是 super 盲人,因为我已经花了最后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>');
}

有任何想法吗?

最佳答案

如果您的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模板文件的完整代码,我可以为您提供帮助。

关于javascript - 聪明的错误不存在吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50157068/

10-12 07:09