Do a truthiness check on references before printing them.

This commit is contained in:
Tom Alexander 2020-05-06 20:30:03 -04:00
parent b45688351e
commit dedfa79630
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 11 additions and 7 deletions

View File

@ -99,13 +99,17 @@ impl<'a> DustRenderer<'a> {
}
DustTag::DTReference(reference) => {
let val = walk_path(breadcrumbs, &reference.path.keys);
let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val)?;
if loop_elements.is_empty() {
// if let Err(RenderError::NotFound { .. }) = val {
// If reference does not exist in the context, it becomes an empty string
return Ok("".to_owned());
} else {
return val?.render(&reference.filters);
match val {
Err(RenderError::NotFound { .. }) => return Ok("".to_owned()),
Ok(final_val) => {
let loop_elements = final_val.get_loop_elements()?;
if loop_elements.is_empty() {
return Ok("".to_owned());
} else {
return final_val.render(&reference.filters);
}
}
Err(render_error) => return Err(render_error),
}
}
DustTag::DTSection(container) => {