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