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

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 {
Err(RenderError::NotFound { .. }) => return Ok("".to_owned()),
Ok(final_val) => {
let loop_elements = final_val.get_loop_elements()?;
if loop_elements.is_empty() { 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()); return Ok("".to_owned());
} else { } else {
return val?.render(&reference.filters); return final_val.render(&reference.filters);
}
}
Err(render_error) => return Err(render_error),
} }
} }
DustTag::DTSection(container) => { DustTag::DTSection(container) => {