-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Export all built-in filters as functions for direct use #464
Comments
And being able to use classes like LiquidTime or TimezoneDate would be helpful too. It's essential for any type of modding Liquidjs. |
I think this makes sense, I can help include this in next version. |
🎉 This issue has been resolved in version 9.35.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
How do you call the builtin filters? I'm trying to use tplEngine.registerFilter("pre", function pre(value: any, ...args: any[]) {
const defaultValue = filters["default"] as FilterHandler;
const valueToPrefix = defaultValue(value, false);
}); I get a TS error for defaultValue saying that |
OK, I think I figured it out now. This is working: import type { FilterHandler } from "liquidjs/dist/src/template/filter-impl-options";
import { Liquid, filters } from "liquidjs";
/** Built-in filter, use in custom filter `append.call(this,...args)` */
const append = filters["append"] as FilterHandler;
/** Built-in filter, use in custom filter `getDefault.call(this,...args)` */
const getDefault = filters["default"] as FilterHandler;
/** Built-in filter, use in custom filter `prepend.call(this,...args)` */
const prepend = filters["prepend"] as FilterHandler;
tplEngine.registerFilter(
"post",
/** An "append" filter that only appends when there is a value. */
function post(value: any, postfix: string) {
value = getDefault.call(this, value, false);
if (value === false) return "";
return append.call(this, value, postfix);
},
);
tplEngine.registerFilter(
"pre",
/** A "prepend" filter that only prepends when there is a value. */
function pre(value: any, prefix: string) {
value = getDefault.call(this, value, false);
if (value === false) return "";
return prepend.call(this, value, prefix);
},
); I also used the following tactic to register a shorter alias to the tplEngine.registerFilter("or", getDefault); I am not sure if there is any difference between accessing the imported |
You’re right. Use .call() or .apply() to pass a proper this. |
I must implement
date_to_xmlschema
from Jekyll and I'd like to callliquidjs/src/builtin/filters/date.ts
Line 7 in 58d0389
The text was updated successfully, but these errors were encountered: