Shopify / liquid

Liquid markup language. Safe, customer facing template language for flexible web apps.
https://shopify.github.io/liquid/
MIT License
11.13k stars 1.39k forks source link

Not support nested objects syntax. #1718

Open liudonghua123 opened 1 year ago

liudonghua123 commented 1 year ago

Hi, I am new to liquid template language. What I want to achieve is like the following code.

<img src={{ '/assets/images/{{entry.logo}}' | relative_url }} class="fas">

But jekyll build failed with some errors like Liquid Exception: Liquid syntax error (/app/src/_includes/docs/app-figure.md line 22): Unexpected character ' in "{{ '/assets/images/docs/{{path}}". Should I rewrite the code using belows? Is there any simple solution for no assign a new variable?

{% assign entry_logo = '/assets/images/{{entry.logo}}' -%}
<img src={{ entry_logo | relative_url }} class="fas">
liudonghua123 commented 1 year ago

I tested on https://geekplayers.com/run-liquild-online.html and using append filter maybe work.

<img src={{ '/assets/images/' | append entry.logo | relative_url }} class="fas">

But how about some complicate expression like '/assets/images/{{dir}}/{{filename}}.{{extension}}'.

'/assets/images/' | append dir | append filename | append '.' | append extension ? It's too ugly.

liudonghua123 commented 1 year ago

Not work either. 😢

Liquid Exception: Liquid syntax error (/app/src/_includes/docs/app-figure.md line 22): Expected end_of_string but found id in "{{ '/assets/images/docs/' | append path | append include.image | relative_url }}" in accessibility-and-localization/accessibility.md.

liudonghua123 commented 1 year ago

In JavaScript, I can use nested template string naturally like this.

a1=123
b=1
`a${b}=${`a${b}`}`
`a${b}=${eval(`a${b}`)}`

Any ideas on how can I write some template code like <img src={{ '/assets/images/{{entry.logo}}' | relative_url }} class="fas">.

liudonghua123 commented 1 year ago

Not work either. 😢

Liquid Exception: Liquid syntax error (/app/src/_includes/docs/app-figure.md line 22): Expected end_of_string but found id in "{{ '/assets/images/docs/' | append path | append include.image | relative_url }}" in accessibility-and-localization/accessibility.md.

Sorry for filter syntax mistake, I forget : after filter name. This method works for me.