Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use hyphens with liquid #1407

Closed
rajpratyush opened this issue Mar 4, 2021 · 5 comments
Closed

Can we use hyphens with liquid #1407

rajpratyush opened this issue Mar 4, 2021 · 5 comments

Comments

@rajpratyush
Copy link

rajpratyush commented Mar 4, 2021

I was rendering a page built with jekyll and liquid and it throwed an error.

here is the html code snippet
<header class="intro-header" style="background-image: url('{{ site.baseurl }}/{% if page.header-img %}{{ page.header-img }}{% else %}{{ site.header-img }}{% endif %}');">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading" style="padding: 30px 0">
<h1>{{ page.title }}</h1>
{% if page.subtitle %}
<h2 class="subheading">{{ page.subtitle }}</h2>
{% endif %}
<span class="meta">Posted by {{ page.author }} on {{ page.date | date: "%B %-d, %Y" }}</span>
</div>
</div>
</div>
</div>
</head>

here is the error message:
Screenshot (692)

my config.yml has:
liquid:
error_mode: strict
strict_variables: true
strict_filters: true

further there is some more error messages that I get are :
[:dot, "."] is not a valid expression in "{{ .spec.host }}"

this was the error message when my config_.yml had

liquid:
error_mode: warn

is it a valid expression??

@dylanahsmith
Copy link
Contributor

Hyphens are allowed in variables. E.g.

irb> Liquid::Template.parse('{% assign a-b = "value" %} {{ a-b }}', error_mode: :strict).render
=> " value"

I think the header-img error you are getting is because of #1034.

The leading . in {{ .spec.host }} doesn't look valid though. Why do you have it there?

It does look like we are missing documentation for what is allowed in a variable name.

@rajpratyush
Copy link
Author

actually the site that was build is unable to render header and footer if you want i can give you the link of the file. so i used strict variables so that i can find where the error is and debug it.

@sebastienros
Copy link

Also, looks like {{ assign [var] = [value] }} is more permissive than {{ [var] }}, for instance this will work even with error_mode: :strict

{% assign $@!$/b = 3 %}{{ b }}

@dylanahsmith
Copy link
Contributor

Also, looks like {{ assign [var] = [value] }} is more permissive than {{ [var] }},

Yeah, strict parsing hasn't been added to the assign tag yet.

@dylanahsmith
Copy link
Contributor

dylanahsmith commented Feb 24, 2022

Looks like this issue is actually a duplicate of #1034, where {% if page.header-img %} is used to check for the presence of the property which results in an error when it doesn't exist and strict_variables is used.

This isn't an issue with hyphens for variables, which does seem to be supported, which can be seen by the variable name in the error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants