How to better understand parameter binding rules
Is this a true limitation or I am just not understanding the usage?
Drogon's CSP Syntax Limitation
The <%view%> directive seems to be primarily for rendering subtemplates, but it doesn't automatically forward variables from the parent context.
Unlike some templating engines (e.g., Jinja2, Django), Drogon requires explicit parameter passing.
This
<%c++
if (!recommendedUsers.empty()) {
for (const auto& user : recommendedUsers) {
%>
<%view user_card_connected user=user %>
<%c++
}
} else {
%>
<p>No recommended users found.</p>
<%c++
}
%>
The user_card_connected.csp holds something like this <hi><%c++ $$ << user.username; %></hi>
Fails to work with the error
keFiles/wahalao.dir/Unity/unity_6_cxx.cxx:22: /Applications/dev/cplusplus/wahalao/build/generated_views/module_network/user_card_connected.cc:23:36: error: use of undeclared identifier 'user' 23 | user_card_connected_tmp_stream << user.username; | ^ 1 error generated. ninja: build stopped: subcommand failed. ✗ C++ build FAILED.
Currently you cannot pass parameters in subview tags. But maybe you can add user parameters like this:
<%c++
if (!recommendedUsers.empty()) {
for (const auto& user : recommendedUsers) {
@@.insert("user",user);
%>
<%view user_card_connected %>
<%c++
}
} else {
%>
<p>No recommended users found.</p>
<%c++
}
%>
Haha. I tried that. But it didn't work.
On Wed, May 28, 2025 at 10:54 AM An Tao @.***> wrote:
an-tao left a comment (drogonframework/drogon#2325) https://github.com/drogonframework/drogon/issues/2325#issuecomment-2914644770
Currently you cannot pass parameters in subview tags. But maybe you can add user parameters like this:
<%c++ if (!recommendedUsers.empty()) { for (const auto& user : recommendedUsers) { @@.insert("user",user); %> <%view user_card_connected %> <%c++ } } else { %>
No recommended users found.
<%c++ } %>— Reply to this email directly, view it on GitHub https://github.com/drogonframework/drogon/issues/2325#issuecomment-2914644770, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEAVD2NHGMSNLXQSDSLM3MT3AUJLZAVCNFSM6AAAAAB6ACGX4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMJUGY2DINZXGA . You are receiving this because you authored the thread.Message ID: @.***>