Reuse `RenderContext` after executing partial
gemhtcr opened this issue · comments
For now, because of the following line of code, handlebars doens't share RenderContext
when rendering partial.
// Rust
let partial = find_partial(rc, r, d, tname)?;
if let Some(t) = partial {
// clone to avoid lifetime issue
// FIXME refactor this to avoid
let mut local_rc = rc.clone(); // <--- This line can't reuse `RenderContext` after partial
// if tname == PARTIAL_BLOCK
let is_partial_block = tname == PARTIAL_BLOCK;
// add partial block depth there are consecutive partial
Is it possible to fix it and have a universal RenderContext
when rendering
?
Yes because partial has its own context data. I'm curious about your use case for reusing the RenderContext
.
Hi @sunng87 , thanks for your update
My case is that I have an assign
helper to assign things to some variable. See below
After spending time tracing source, it seems to me the closest solution is to add it into RenderContext
so that it can be seen by parent context
I'm happy to learn if there is other way to achieve this
I think it's not possible also it's not recommended to have data modification in templates, which has poor debug experience. I will suggest you to prepare the data ahead of rendering and feed to the template directly.