@@ -143,6 +143,29 @@ Builder(
143143 helpers::registerAntoraHelpers (hbs_);
144144 helpers::registerLogicalHelpers (hbs_);
145145 helpers::registerContainerHelpers (hbs_);
146+
147+ // load templates
148+ exp = forEachFile (layoutDir (), false ,
149+ [&](std::string_view pathName) -> Expected<void >
150+ {
151+ // Get template relative path
152+ std::filesystem::path relPath = pathName;
153+ relPath = relPath.lexically_relative (layoutDir ());
154+
155+ // Skip non-handlebars files
156+ MRDOCS_CHECK_OR (relPath.extension () == " .hbs" , {});
157+
158+ // Load template contents
159+ MRDOCS_TRY (std::string text, files::getFileText (pathName));
160+
161+ // Register template
162+ this ->templates_ .emplace (relPath.generic_string (), text);
163+ return {};
164+ });
165+ if (!exp)
166+ {
167+ exp.error ().Throw ();
168+ }
146169}
147170
148171// ------------------------------------------------
@@ -154,8 +177,9 @@ callTemplate(
154177 std::string_view name,
155178 dom::Value const & context)
156179{
157- auto pathName = files::appendPath (layoutDir (), name);
158- MRDOCS_TRY (auto fileText, files::getFileText (pathName));
180+ auto it = templates_.find (name);
181+ MRDOCS_CHECK (it != templates_.end (), formatError (" Template {} not found" , name));
182+ std::string_view fileText = it->second ;
159183 HandlebarsOptions options;
160184 options.escapeFunction = escapeFn_;
161185 OutputRef out (os);
0 commit comments