pub struct Helper<'rc> { /* private fields */ }
Expand description
Render-time Helper data when using in a helper definition
Implementations§
Source§impl<'reg: 'rc, 'rc> Helper<'rc>
impl<'reg: 'rc, 'rc> Helper<'rc>
Sourcepub fn params(&self) -> &Vec<PathAndJson<'rc>>
pub fn params(&self) -> &Vec<PathAndJson<'rc>>
Returns all helper params, resolved within the context
Sourcepub fn param(&self, idx: usize) -> Option<&PathAndJson<'rc>>
pub fn param(&self, idx: usize) -> Option<&PathAndJson<'rc>>
Returns nth helper param, resolved within the context.
§Example
To get the first param in {{my_helper abc}}
or {{my_helper 2}}
,
use h.param(0)
in helper definition.
Variable abc
is auto resolved in current context.
use handlebars::*;
fn my_helper(h: &Helper, rc: &mut RenderContext) -> Result<(), RenderError> {
let v = h.param(0).map(|v| v.value())
.ok_or(RenderErrorReason::ParamNotFoundForIndex("myhelper", 0));
// ..
Ok(())
}
Sourcepub fn hash(&self) -> &BTreeMap<&'rc str, PathAndJson<'rc>>
pub fn hash(&self) -> &BTreeMap<&'rc str, PathAndJson<'rc>>
Returns hash, resolved within the context
Sourcepub fn hash_get(&self, key: &str) -> Option<&PathAndJson<'rc>>
pub fn hash_get(&self, key: &str) -> Option<&PathAndJson<'rc>>
Return hash value of a given key, resolved within the context
§Example
To get the first param in {{my_helper v=abc}}
or {{my_helper v=2}}
,
use h.hash_get("v")
in helper definition.
Variable abc
is auto resolved in current context.
use handlebars::*;
fn my_helper(h: &Helper, rc: &mut RenderContext) -> Result<(), RenderError> {
let v = h.hash_get("v").map(|v| v.value())
.ok_or(RenderErrorReason::ParamNotFoundForIndex("my_helper", 0));
// ..
Ok(())
}
Sourcepub fn template(&self) -> Option<&'rc Template>
pub fn template(&self) -> Option<&'rc Template>
Returns the default inner template if the helper is a block helper.
Typically you will render the template via: template.render(registry, render_context)
Sourcepub fn is_block(&self) -> bool
pub fn is_block(&self) -> bool
Returns if the helper is a block one {{#helper}}{{/helper}}
or not {{helper 123}}
Sourcepub fn has_block_param(&self) -> bool
pub fn has_block_param(&self) -> bool
Returns if the helper has either a block param or block param pair
Sourcepub fn block_param(&self) -> Option<&'rc str>
pub fn block_param(&self) -> Option<&'rc str>
Returns block param if any
Sourcepub fn block_param_pair(&self) -> Option<(&'rc str, &'rc str)>
pub fn block_param_pair(&self) -> Option<(&'rc str, &'rc str)>
Return block param pair (for example |key, val|) if any
Trait Implementations§
Auto Trait Implementations§
impl<'rc> Freeze for Helper<'rc>
impl<'rc> RefUnwindSafe for Helper<'rc>
impl<'rc> Send for Helper<'rc>
impl<'rc> Sync for Helper<'rc>
impl<'rc> Unpin for Helper<'rc>
impl<'rc> UnwindSafe for Helper<'rc>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)