Skip to content

Support liquid strict_variables #25

@nathanweeks

Description

@nathanweeks

When developing a Jekyll site, it can be useful to set the Liquid strict_variables option to prevent accidentally using an undefined variable (e.g., typo, or when a property that is expected to exist in a data file doesn't actually exist). However, there are a number of places in this theme where a variable / property can optionally exist---checked for with an if tag---and the Liquid implementation used by Jekyll has a bug that causes an exception to be thrown when the existence of an undefined variable is checked for in this manner.

Enabling strict_variables in _config.yml:

liquid:
  strict_variables: true

Results in the following error:

$ bundle exec jekyll serve
...
  Liquid Exception: Liquid error (line 1): undefined variable tools_menu in /workspaces/jekyll-starter-legumeinfo/_themes/jekyll-theme-legumeinfo/_layouts/default.html
                    ------------------------------------------------
      Jekyll 4.2.2   Please append `--trace` to the `serve` command 
                     for any additional information or backtrace. 
                    ------------------------------------------------
/usr/local/rvm/gems/ruby-3.2.2/gems/liquid-4.0.4/lib/liquid/variable_lookup.rb:62:in `block in evaluate': Liquid error (line 1): undefined variable tools_menu (Liquid::UndefinedVariable)
...

A workaround (in most cases) is to use the contains operator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions