Assign {{data}} from article content

Highlighted
Shopify Partner
6 0 0

Hi,
Can anybody please help me with an idea on how to assign {{}} data from article?
I have a piece of code on article.liquid which I want to fill up with data {{xxxxxxx}}, {{yyyyyyyyy}}, {{zzzzzzzzzzz}}.
I need to change those data from article content. How can I use {% assign xxxxxxx ....................... that can be change from article content, not article.liquid?
Thanks

0 Likes
Highlighted
Shopify Expert
656 46 142

Use assign to assign a value to a variable, like this:

{% assign trees = "are cool" %}

To access data from the article object, use liquid, for example:

<h3>Author</h3>
<p>{{ article.author }}</p>

Reference: https://shopify.dev/docs/liquid/reference/objects/article

Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Theme Scientist (A/B testing app).
Creator of Order Automator (app that auto tags + fulfills orders, send emails).
Creator of Tip Jar (add a tip button to your store).
Creator of Shopify Analyzer (free performance analysis tool).
I also build custom apps and automated solutions.
Enjoy the adventure!
0 Likes
Highlighted
Shopify Partner
6 0 0

Hi, JoesIdeas,
Thanks for your reply.

Unfortunately, I need just the opposite: to access custom info from the article content, in the article.liquid..

I end up using this:

In the article, I`ve created labels with data I can customize:

<lable data1="custom data 1a, custom data 1b, custom data 1c"></lable> \\this is invisible in the article content
<lable data2="custom data 2a, custom data 2b, custom data 2c"></lable> \\this is invisible in the article content

In the article.liquid I`ve used:

{% capture infoLable %}{{article.content}}{% endcapture %} \\ this capture the content
{% assign data1 = infoLable | split:'<lable data1="' | last | split:'"' | first | split: ", " %} \\this create array with info from data1
{% assign data2 = infoLable | split:'<lable data2="' | last | split:'"' | first | split: ", " %} \\this create array with info from data2

And now I can use {{ data1 [0] }} {{ data1 [1] }} {{ data1 [2] }} or {{ data2 [0] }} {{ data2 [1] }} {{ data2 [2] }} to access the info from article lable data content.

I dont know if this is the best way, but it works for the moment :)

Thanks

0 Likes