You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However slots that are empty by default must be filled to avoid getting a missing-partial error:
(See handlebars repo here and here.)
Example:
/partials/templates/article.hbs:
<div>
{{>empty-by-default-top-slot}}{{#>filled-by-default-slot}}{{! Some widget or whatever}}{{/filled-by-default-slot}}{{>content_loop_or_whatever}}{{>empty-by-default-end-slot}}
</div>
If I do not want to pass content to some slots, I need to pass an empty partial.
A theme using inline partials can have many optional slots. This makes the templates overly verbose and cumbersome, almost on par with passing bool-variables to the template to if-test. However a helper to check if the partial is defined would simplify the process by either passing content or not, like so:
// # Partial helper to test if inline partials are defined in scope.// // Usage: `{{#if (is_partial_defined "slot-name"}}{{>slot-name}}{{/if}}`//// Returns true if a partial is defined, otherwise falseconstinstance=require("../services/theme-engine/engine");consterrors=require('@tryghost/errors');consttpl=require('@tryghost/tpl');constmessages={partialNameMissing:
"The {{is_partial_defined}} helper must be passed a partial name",};module.exports=functionis_partial_defined(partialName,options){if(!partialName){thrownewerrors.IncorrectUsageError({message: tpl(messages.partialNameMissing),});}if(instance.handlebars.partials[partialName]===undefined){returnfalse;}else{returntrue;}};
I know you have a strict policy on custom expansions across the board, which is appreciated, but I am kind of hoping for this one, as it's more of a "core" theme-developer-geared thing. You decide! =)
Thanks,
Flemming
The text was updated successfully, but these errors were encountered:
Hi guys,
Using inline partials to fill up slots in another partial is a fantastic feature when developing themes.
See https://handlebarsjs.com/guide/partials.html#inline-partials
However slots that are empty by default must be filled to avoid getting a missing-partial error:
(See handlebars repo here and here.)
Example:
/partials/templates/article.hbs
:If I do not want to pass content to some slots, I need to pass an empty partial.
/page.hbs
:A theme using inline partials can have many optional slots. This makes the templates overly verbose and cumbersome, almost on par with passing bool-variables to the template to if-test. However a helper to check if the partial is defined would simplify the process by either passing content or not, like so:
There is a stalled pull for this in handlebars:
handlebars-lang/handlebars.js#1953
And here is the ghost rewrite I currently use:
I know you have a strict policy on custom expansions across the board, which is appreciated, but I am kind of hoping for this one, as it's more of a "core" theme-developer-geared thing. You decide! =)
Thanks,
Flemming
The text was updated successfully, but these errors were encountered: