Output of the template engine syntax {% ELSEIF %} through the array JS back to the template

Viewed 26

I have in the template {% ELSEIF goods_features.NAME=Snikers %}<img data-fancybox data-caption="Caption..." data-src="pic.jpg" src="pic.jpg" alt="{goods_features.NAME}" /> and there are a lot of such ELSEIF! I decided to optimize everything through JSON and array jQuery:

// CANDY JSON
$(function() {

    var candyList = $("#candyList");
    var candyList2 = $("#candyList2");
    var url = "/candy.txt";

    // Read JSON file
    $.getJSON(url, function(data) {

        candyList.empty();
        candyList2.empty();

        // Format tags HTML
        for(var i in data.candy) {
            var elseIf = "{% ELSEIF goods_features.NAME=" + data.candy[i].candyname + " %}";
            var content = elseIf + `<img data-fancybox data-caption="${data.candy[i].candycaption}" data-src="${data.candy[i].candyimg}" src="${data.candy[i].candyimg}" alt="{goods_features.NAME}" />`;
            var content2 = elseIf + `<div class="cuttedText" title="${data.candy[i].candycaption}">${data.candy[i].candycaption}</div>`;
            candyList.append(content);
            candyList2.append(content2);
        }
    });
});

{% ELSEIF goods_features.NAME=Snikers %} it is output as TEXT on the page and, accordingly, does not work in the template. Tell me, how can I fix it?

also, the JS array is not executed as a template engine array

{% FOR goods_features %}
<div class="features__item flex" style="{% IF goods_features.NAME=min order || goods_features.NAME=sale to %}display: none;{% ENDIF %}">
   <div class="features__name">
      {% IF goods_features.NAME=Mars %}<img data-fancybox data-caption="Caption..." data-src="39479.webp" src="39479.webp" alt="{goods_features.NAME}" />
      <div id=candyList> **JS array (candyList)** </div>
      {% ENDIF %}

      <span>{goods_features.NAME}</span>
      {% IF goods_features.NAME=Mars %}
      <div class="cuttedText" title="Caption...">Caption...</div>
      <div id="candyList2"> **JS array (candyList2)** </div>
      {% ENDIF %}
   </div>
   <div class="features__value">
      <span>{goods_features.VALUE}</span>
   </div>
</div>
{% ENDFOR %}
0 Answers
Related