pub struct IfEmptyHelper;
Expand description
Call the template if an empty or whitespaces string is passed as parameter
assert_eq!(
exec_template(json!({"a": 42}), "{{#if_empty a}}OK{{else}}NOK{{/if_empty}}"),
"NOK"
);
assert_eq!(
exec_template(json!({}), "{{#if_empty \"42\"}}OK{{else}}NOK{{/if_empty}}"),
"NOK"
);
assert_eq!(
exec_template(json!({}), "{{#if_empty \" \"}}OK{{else}}NOK{{/if_empty}}"),
"OK"
);
assert_eq!(
exec_template(json!({}), "{{#if_empty not_existing}}OK{{else}}NOK{{/if_empty}}"),
"OK"
);
assert_eq!(
exec_template(json!({"plop": "plop"}), "{{#if_empty plop}}OK{{else}}NOK{{/if_empty}}"),
"NOK"
);
assert_eq!(
exec_template(json!({"plop": ""}), "{{#if_empty plop}}OK{{else}}NOK{{/if_empty}}"),
"OK"
);
assert_eq!(
exec_template(json!({"plop": "plop"}), "{{#if_empty not_existing}}OK{{else}}NOK{{/if_empty}}"),
"OK"
);
Trait Implementations§
Source§impl HelperDef for IfEmptyHelper
impl HelperDef for IfEmptyHelper
Source§fn call<'reg: 'rc, 'rc>(
&self,
h: &Helper<'reg, 'rc>,
handle: &'reg Handlebars<'reg>,
ctx: &'rc Context,
render_ctx: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult
fn call<'reg: 'rc, 'rc>( &self, h: &Helper<'reg, 'rc>, handle: &'reg Handlebars<'reg>, ctx: &'rc Context, render_ctx: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output, ) -> HelperResult
A complex version of helper interface. Read more
Source§fn call_inner<'reg, 'rc>(
&self,
_: &Helper<'reg, 'rc>,
_: &'reg Registry<'reg>,
_: &'rc Context,
_: &mut RenderContext<'reg, 'rc>,
) -> Result<ScopedJson<'reg, 'rc>, RenderError>where
'reg: 'rc,
fn call_inner<'reg, 'rc>(
&self,
_: &Helper<'reg, 'rc>,
_: &'reg Registry<'reg>,
_: &'rc Context,
_: &mut RenderContext<'reg, 'rc>,
) -> Result<ScopedJson<'reg, 'rc>, RenderError>where
'reg: 'rc,
A simplified api to define helper Read more
Auto Trait Implementations§
impl Freeze for IfEmptyHelper
impl RefUnwindSafe for IfEmptyHelper
impl Send for IfEmptyHelper
impl Sync for IfEmptyHelper
impl Unpin for IfEmptyHelper
impl UnwindSafe for IfEmptyHelper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more