DEV
Views & templates
Templates live in view/, are compiled by the CLI and rendered from controllers.
Template syntax
Templates embed C++ with <%c ... %>; data comes from the controller’s client.val.
view/cms/list.htmlhtml
<html>
<body>
<h1><%c echo obj["title"].to_string(); %></h1>
<%c if (obj["list"].is_array()) { %>
<%c for (auto &row : obj["list"].as_array()) { %>
<p><%c echo row["name"].to_string(); %></p>
<%c } %>
<%c } %>
</body>
</html>Compile templates
terminalbash
# Build templates into viewsrc/
./bin/paozhu_cli view # incremental
./bin/paozhu_cli view force # full rebuild
# Then rebuild the C++ target
cd build && make -j8Render from a controller
controller/src/article_list.cppcpp
auto articles = orm::cms::Article();
articles.where("isopen", 1).fetch();
client.val["title"] = "Article list";
client.val["list"].set_array();
for (auto &row : articles) {
obj_val item;
item["name"] = row.title;
client.val["list"].push(std::move(item));
}
peer->view("cms/list");Themes and SaaS
theme_view() prefixes view paths with the site’s themes value. get_theme() and get_themeurl() expose site-level asset prefixes, the basis for SaaS theming.