8

Is there a way to have a variable within a statement in liquid so that something like the following:

{% assign somevar = 'about-us' %}
{{ pages.somevar.content }}

would result in the same output as if you had originally used:

{{ pages.about-us.content }}
3
  • I don't think you can do that. You could perhaps try something like {{ pages.#{somevar}.content }}
    – csaunders
    Commented Mar 26, 2013 at 15:55
  • Thanks for the suggestion. That gives a parse error as follows: There were errors saving your file: Variable '{{ pages.#{somevar}' was not properly terminated with regexp: /\}\}/ Commented Mar 26, 2013 at 17:23
  • So I don't think you are going to be able to do what you want. At least from what I understand you are trying to do in your question.
    – csaunders
    Commented Mar 26, 2013 at 17:55

1 Answer 1

17
{% assign somevar = 'about-us' %}
{{ pages.[somevar].content }}

That works fine for me...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.