jekyllliquidnested-includes

Passing parameters between nested includes


I want to be able to pass parameters from one include to another. However, Jekyll doesn't seem to like this.

index.md

{% include test-wrapper.html test-var='Foo' %}

test-wrapper.html

{% include test.html test-var={{ include.test-var }} %}

test.html

Got {{ test-var }}

Terminal output

$ bundle exec jekyll build --incremental --trace
Configuration file: /Path/to/project/_config.yml
            Source: /Path/to/project
       Destination: /Path/to/project/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
  Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: test.html test-var=Foo Valid syntax: {% include file.ext param='value' param2='value' %} in index.md
bundler: failed to load command: jekyll (/usr/local/bin/jekyll)
ArgumentError: Invalid syntax for include tag. File contains invalid characters or sequences:

  test.html test-var=Foo

Valid syntax:

  {% include file.ext param='value' param2='value' %}


  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:67:in `validate_file_name'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:128:in `render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:140:in `block in render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/context.rb:123:in `stack'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/tags/include.rb:137:in `render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
  /Library/Ruby/Gems/2.3.0/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:126:in `render_liquid'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:79:in `render_document'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:62:in `run'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:479:in `render_regenerated'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:472:in `block in render_pages'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:471:in `each'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:471:in `render_pages'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:192:in `render'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:71:in `process'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/command.rb:28:in `process_site'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:65:in `build'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:36:in `process'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
  /Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
  /Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
  /Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
  /Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
  /Library/Ruby/Gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
  /Library/Ruby/Gems/2.3.0/gems/jekyll-3.8.5/exe/jekyll:15:in `<top (required)>'
  /usr/local/bin/jekyll:22:in `load'
  /usr/local/bin/jekyll:22:in `<top (required)>'

Solution

  • test-wrapper.html

    {% include test.html test-var=include.test-var %}
    

    test.html

    Got {{ include.test-var }}