Умная ошибка, которой там нет? - PullRequest
0 голосов
/ 03 мая 2018

Я получаю сообщение об ошибке, которого, по сути, здесь нет, или я супер слепой, потому что я потратил на это последние 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 голосов
/ 19 июня 2018

Вы должны обернуть свой JS-код в тег {literal}, если он находится в файле шаблона Smarty. Ваш код должен быть:

{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 в своем вопросе, я могу вам помочь.

...