I’m currently using LiquidJS and I’m trying to implement the following behavior:
- I want to pass an object to a custom tag and receive the full object in the tag.
- If the same object is rendered in the final template (i.e., without being passed to a tag), I want to retrieve a string by looking up data from a database and returning a specific value.
Example Scenario:
Let’s say I have an object structured like this:
{
"Value": "12345",
"Type": "user"
}
- If this object is passed to a custom tag, I expect the tag to receive the entire object so that I can use the Value and Type inside the tag function.
- However, if this object is directly rendered in the template (i.e., via
{{ object }}), I want it to trigger a lookup in the database (in this case, using the Value field to find the firstName and lastName of the user) and return a string with the user's name.
Specific Questions:
Is it possible to achieve this behaviour using Drops and toLiquid() and/or valueOf() in LiquidJS?
- I tried returning an object in the toLiquid() function, but the only way that worked was by defining a key. So if I defined name to be the function that does the db lookup, then when rendering
{{ object.name }} it worked. But I want to have this behaviour without having to add ".name" and simply have {{ object }}.
- What happens when an object is set using the
{% capture %} tag? If I use the {% capture %} tag to store this object in a variable, will the captured variable hold the entire object (with its Value and Type fields), or will it contain the rendered string (the user's name after the database lookup)?
{% capture userVar %}
{{ object }}
{% endcapture %}
Would userVar hold the object or the rendered string (e.g., "John Doe")?
I’m currently using LiquidJS and I’m trying to implement the following behavior:
Example Scenario:
Let’s say I have an object structured like this:
{ "Value": "12345", "Type": "user" }{{ object }}), I want it to trigger a lookup in the database (in this case, using the Value field to find the firstName and lastName of the user) and return a string with the user's name.Specific Questions:
Is it possible to achieve this behaviour using Drops and toLiquid() and/or valueOf() in LiquidJS?
{{ object.name }}it worked. But I want to have this behaviour without having to add ".name" and simply have{{ object }}.{% capture %}tag? If I use the{% capture %}tag to store this object in a variable, will the captured variable hold the entire object (with its Value and Type fields), or will it contain the rendered string (the user's name after the database lookup)?{% capture userVar %} {{ object }} {% endcapture %}Would userVar hold the object or the rendered string (e.g., "John Doe")?