1
votes

I am editing a shopify template liquid page where inside is consisting of the

{%raw%} {{item}} {% endraw %}

I tested the code by adding :

{%raw%} {% assign myvar = {{item}} %} {{myvar}} {% endraw %}

instead its printing all of it as a raw html, is there anyway that I can overcome this as I need to get the variable printed out in that specific tag

thank you!

update :

  {% raw %}
    <form action="/cart" method="post" novalidate class="cart ajaxcart">
      <div class="ajaxcart__inner">
        {{#items}}
        <div class="ajaxcart__product">
          <div class="ajaxcart__row" data-line="{{line}}">
            <div class="grid">
              <div class="grid__item one-quarter">
                <a href="{{url}}" class="ajaxcart__product-image"><img src="{{img}}" alt=""></a>
              </div>
              <div class="grid__item three-quarters item-meta">
                <div class="grid--full display-table">
                  <div class="grid__item display-table-cell three-quarters cart-item">

                      <a href="{{url}}" class="ajaxcart__product-name">
                        {{name}}
                      </a>

something like this but once I removed the raw tags somehow the content inside are not rendering??

1
The idea of {% raw %} is to output the liquid code as a text. If you like to output the liquid code, don't use it between {% raw %} tag.drip
Can you please supply more of the surrounding code and some clarification on what you're actually trying to do? It looks like you're trying to do something to a template that will be rendered through Javascript, which runs after all of the Liquid code has been parsed - so even if your assign worked, all you would get is the literal string {{item}}, which I doubt is what you want.Dave B
@DaveB I updated the code with the surrounding wrapper, thank youBoby
That looks like code from one of the Timber-family of themes - like Supply or Brooklyn or one of their related themes. Those are all placeholders for Javascript variables, not Liquid variables. Liquid is only rendered once, at page load, whereas that template that you're looking at is used to do live-updates to the page any time the shopper changes their cart contents. If you want new variables in there, you'll need to add them through the main javascript file - usually named "app.js" or "theme.js" and found in your theme's Assets folder.Dave B
@DaveB you are right! its on that part of functions :) I found it and revised and added what needs to be added thank you for helping out!Boby

1 Answers

1
votes

It looks like you're trying to do something to a template that will be rendered through Javascript, which runs after all of the Liquid code has been parsed - so even if your assign worked, all you would get is the literal string {{item}}, which I doubt is what you want.

That looks like code from one of the Timber-family of themes - like Supply or Brooklyn or one of their related themes. Those are all placeholders for Javascript variables, not Liquid variables. Liquid is only rendered once, at page load, whereas that template that you're looking at is used to do live-updates to the page any time the shopper changes their cart contents. If you want new variables in there, you'll need to add them through the main javascript file - usually named "app.js" or "theme.js" and found in your theme's Assets folder.

If I'm right about the theme family, you should find a function in the core theme file named buildCart, which builds up information that gets passed to that template. If you add new variables to the object that buildCart sends to that template, you can put placeholders for your new variables as {{ myVar }} for text display and {{{ myVar }}} if your variable contains HTML formatting