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

added a helper to check if a partial is defined in the context #1948 #1953

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/handlebars/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import registerIf from './helpers/if';
import registerLog from './helpers/log';
import registerLookup from './helpers/lookup';
import registerWith from './helpers/with';
import registerPartialDefined from './helpers/partial-defined'

export function registerDefaultHelpers(instance) {
registerBlockHelperMissing(instance);
Expand All @@ -14,6 +15,7 @@ export function registerDefaultHelpers(instance) {
registerLog(instance);
registerLookup(instance);
registerWith(instance);
registerPartialDefined(instance);
}

export function moveHelperToHooks(instance, helperName, keepHelper) {
Expand Down
16 changes: 16 additions & 0 deletions lib/handlebars/helpers/partial-defined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Exception } from '@handlebars/parser';

export default function (instance) {
instance.registerHelper('partialDefined', function (partialName, options) {
if (arguments.length != 2) {
throw new Exception('#partialDefined requires exactly one argument');
}

if (instance.partials[partialName] === undefined) {
return false
} else {
return true
}

});
}