-
-
Notifications
You must be signed in to change notification settings - Fork 147
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Introduction
"each_row" helper cannot contain calls to inline partials.
To Reproduce
{{#*inline "item" }}
<li>{{ this }}</li>
{{/inline}}
<ul>
{{#each_row }}
{{> item }}
{{/each_row }}
</ul>
select
'foo' as component;
select
'a' as item;
select
'b' as item;
select
'c' as item;
Actual behavior
After following these steps, this error message shows up on the web page:
Partial not found item
Version information
- OS: Linux Debian 11
- PostgreSQL 17
- SQLPage 0.33.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
lovasoa commentedon Mar 6, 2025
The issue you're experiencing with inline partials not working inside
each_row
helpers is due to how SQLPage processes templates internally.In SQLPage the template rendering process involves splitting templates into three parts:
When SQLPage encounters an
each_row
helper, it splits the template at that point using thesplit_template
function. This function extracts the content inside theeach_row
block into a separate template (list_content
), with everything before it going intobefore_list
and everything after intoafter_list
.The problem occurs because inline partials defined with
{{#*inline "name"}}...{{/inline}}
are registered in the Handlebars registry during the initial template parsing. However, when the template is split, these inline partial definitions remain in thebefore_list
section, but thelist_content
template (which contains youreach_row
content) becomes a separate template context that doesn't have access to those inline partials.In the
render_item
method ofSplitTemplateRenderer
, when it tries to render each row, it's using the isolatedlist_content
template which can't see the inline partials defined in the parent template.This is why you're seeing the "Partial not found item" error - the
{{> item }}
reference inside youreach_row
block is looking for a partial that isn't accessible from that context.Possible workarounds:
each_row
block instead of a partial#each_row
This is a limitation of how SQLPage processes templates to support its streaming row-by-row rendering model, which is different from standard Handlebars processing.
mesr commentedon Mar 7, 2025
Thank you @lovasoa for this detailed answer. This is very useful information indeed. Workaround 1 is not applicable to our use case, as it would lead to a lot of hard-to-maintain duplication of code. Workaround 2, even though not ideal, is a workable solution. So, thanks again and keep up the good work!