Skip to content

Commit

Permalink
fix(whiskers): use block context in darklight helper (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
backwardspy authored Mar 5, 2024
1 parent 8e60740 commit 486a747
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions whiskers/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn darklight(
h: &Helper,
_r: &Handlebars,
ctx: &Context,
_rc: &mut RenderContext,
rc: &mut RenderContext,
out: &mut dyn Output,
) -> HelperResult {
let dark = h
Expand All @@ -101,7 +101,13 @@ pub fn darklight(
.param(1)
.ok_or_else(|| RenderErrorReason::ParamNotFoundForIndex("darklight", 1))?;

if ctx.data()["flavor"] == "latte" {
// if we're in an each block, we have to try and get the flavor from the iteration key
let flavor = rc
.block()
.and_then(|block| block.get_local_var("key"))
.unwrap_or_else(|| &ctx.data()["flavor"]);

if flavor == "latte" {
out.write(&light.render())?;
} else {
out.write(&dark.render())?;
Expand Down

0 comments on commit 486a747

Please sign in to comment.