eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Handlebars url filter stopped working

Open marcinwrochna opened this issue 2 years ago • 0 comments

Compiling a handlebars file using the url filter, like say input/index.md with

<a href="{{ url '/upload/foo.pdf' }}">foo</a>

fails with an error:

[11ty] 1. Having trouble rendering hbs template ./input/index.md (via TemplateContentRenderError)
[11ty] 2. pathPrefix (String) is required in the `url` filter. (via Error)

This happens both when the path prefix is set through the command line with --pathprefix="/bar/" or through config (return {..., pathPrefix: "/bar/"}).

Stack trace

[11ty] Original error stack trace: Error: pathPrefix (String) is required in the `url` filter.
[11ty]     at Object.module.exports (/home/token0/workspace/test/node_modules/@11ty/eleventy/src/Filters/Url.js:25:11)
[11ty]     at Object.<anonymous> (/home/token0/workspace/test/node_modules/@11ty/eleventy/src/defaultConfig.js:16:22)
[11ty]     at Object.<anonymous> (/home/token0/workspace/test/node_modules/@11ty/eleventy/src/BenchmarkGroup.js:32:26)
[11ty]     at Object.wrapper (/home/token0/workspace/test/node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js:15:19)
[11ty]     at Object.eval [as main] (eval at createFunctionContext (/home/token0/workspace/test/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:262:23), <anonymous>:11:139)
[11ty]     at main (/home/token0/workspace/test/node_modules/handlebars/dist/cjs/handlebars/runtime.js:208:32)
[11ty]     at ret (/home/token0/workspace/test/node_modules/handlebars/dist/cjs/handlebars/runtime.js:212:12)
[11ty]     at ret (/home/token0/workspace/test/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:519:21)
[11ty]     at /home/token0/workspace/test/node_modules/@11ty/eleventy/src/Engines/Handlebars.js:60:14
[11ty]     at /home/token0/workspace/test/node_modules/@11ty/eleventy/src/Engines/Markdown.js:73:47
[11ty] Using pathPrefix: /bar/

Indeed, adding console.log(pathPrefix) in the function in Url.js shows that the function argument "pathPrefix" is actually:

{
  lookupProperty: [Function: lookupProperty],
  name: 'url',
  hash: {},
  data: {
    root: {
      eleventy: [Object],
      pkg: [Object],
      page: [Object],
      collections: [Object]
    }
  },
  loc: { start: { line: 1, column: 9 }, end: { line: 1, column: 44 } }
}

Environment: Tested on a fresh new install: Eleventy 1.0.2 (Linux, npm 8.19.1), [email protected]. It worked OK with Eleventy 0.12.1, same handlebars version. Works fine with liquid templating.

marcinwrochna avatar Sep 11 '22 20:09 marcinwrochna