Skip to content

Shortcode arguments not passed correctly when called from liquid layout #2348

@lexoyo

Description

@lexoyo

Hello

Thank you for this great tool, we do good and things with it (social and environmental) and I have a lot of fun 🙏

Describe the bug

When using shortcodes in liquid, the parameters are not passed correctly to the js function

To Reproduce

$ git clone git@github.com:11ty/eleventy-base-blog.git
$ cd eleventy-base-blog
$ npm i && npm start

Then in another terminal window

$ echo '{% image "NJK", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8", "arg9" %}' > _includes/layouts/post.njk
$ echo '{% image "LIQUID", "arg2", "arg3", "arg4" "arg5" "arg6" "arg7" "arg8" "arg9" %}' > _includes/layouts/post.liquid

In .eleventy.js I add this line: eleventyConfig.addShortcode("image", (...args) => console.log('image', args));

The output at this stage is correct:

image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]

In posts/firstpost.md I set layout to layouts/post.liquid, then the output is still correct

image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [ 'LIQUID', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6', 'arg7', 'arg8', 'arg9' ]

Finally in posts/secondpost.md I set layout to layouts/post.liquid, then the output is NOT correct anymore

image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [
  'NJK', 'arg2',
  'arg3',    'arg4',
  'arg5',    'arg6',
  'arg7',      'arg8',
  'arg9'
]
image [ 'LIQUID', 'arg2', 'arg4', 'arg6', 'arg8' ]
image [ 'LIQUID', 'arg3', 'arg5', 'arg7', 'arg9' ]

Expected behavior

The arguments should be passed 2 times the same and the output would be

image [ 'LIQUID', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6', 'arg7', 'arg8', 'arg9' ]
image [ 'LIQUID', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6', 'arg7', 'arg8', 'arg9' ]

instead of

image [ 'LIQUID', 'arg2', 'arg4', 'arg6', 'arg8' ]
image [ 'LIQUID', 'arg3', 'arg5', 'arg7', 'arg9' ]

Environment:

  • OS and Version: Linux
  • Eleventy Version: 1.0.1

Additional context
If I add one more page using the liquid template it outputs something like this

image [ 'LIQUID', 'arg4', 'arg7' ]
image [ 'LIQUID', 'arg2', 'arg5', 'arg8' ]
image [ 'LIQUID', 'arg3', 'arg6', 'arg9' ]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions