Frontend need for Handlebars.compile. but handlebars already in use with bigcommerce serverside

痞子三分冷 提交于 2019-12-12 06:17:32

问题


I am developing a bigcommerce stencil theme. I want to use basic handlebars functionality like

markup

    <div id="mobile"></div>
    <script id="mobile_category_template" type="text/x-handlebars-template">
      <div class="entry">
        <h1>{{var}}</h1>
        <div class="body">
          <p>body</p>
        </div>
      </div>
    </script>
    <script src="{{cdn 'https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.min.js'}}"></script>
    <script src="{{cdn '/assets/js/category.js'}}"></script>

javascript

    var hitTemplate = Handlebars.compile($("#mobile_category_template").html());
    $(".collection-page").html(hitTemplate({
      var: "var works"
    }));

This would normally work. but bigcommerce parses handlebars serverside. By the time my frontend handlebars parse, the {{var}} has already been compiled. How can i get the above to work separately from serverside handlebars? OR how do i make and/or extend the current handlebars logic. (basically how can define my own template variables/drops)

Very specifically. I want to decide rather to load {{> components/mobile}} or {{> components/desktop}} based on the viewport or browser in use (easily done with javascript).

This is the problem i want to solve: BigCommerce Stencil — load component parts based on custom javascript logic

来源:https://stackoverflow.com/questions/44634630/frontend-need-for-handlebars-compile-but-handlebars-already-in-use-with-bigcomm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!