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

PairedShortcode being called out of order #3510

Open
kingmesal opened this issue Oct 25, 2024 · 0 comments
Open

PairedShortcode being called out of order #3510

kingmesal opened this issue Oct 25, 2024 · 0 comments

Comments

@kingmesal
Copy link

kingmesal commented Oct 25, 2024

Operating system

Linux

Eleventy

3.0.0

Describe the bug

Given these codes:

  eleventyConfig.addPairedShortcode("firstTruthy", function (content: string, ...items: Array<any>) {
      const options: HandlebarsOptions = items.pop();
      const firstTruthyValue = items.find((item) => !!item); // Find first truthy value

      if (firstTruthyValue) {
        return options.fn(firstTruthyValue);
      }

      return "";
    },
  );

  eleventyConfig.addShortcode("test", function (value: string) {
    console.log(value);
  });

If I put this into my header.hbs:

{{#firstTruthy happy boring "/static/image/file.png" }}
    {{#firstTruthy this "value" }}
        {{ test this }}
    {{/firstTruthy}}
{{/firstTruthy}}

The test method gets called before firstTruthy. If I change the firstTruthy method to be a Shortcode instead of PairedShortcode the ordering works correctly.

If I change that header.hbs:

{{#firstTruthy happy boring "/static/image/file.png" }}
    {{#firstTruthy this "value" }}
        {{ this }}
    {{/firstTruthy}}
{{/firstTruthy}}

Just not calling that test shortcode, it works as expected.

Reproduction steps

All the example code is provided.

I am using handlebars as my templates. I'm using the latest
"@11ty/eleventy-plugin-handlebars": "^1.0.0",

I had to attach my debugger to the environment to figure out why that test method was received an object this instead of the string.

Expected behavior

The inner test method should only be called after the outer paired shortcodes execute.

Reproduction URL

No response

Screenshots

No response

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

2 participants
@kingmesal and others