use*_*473 3 html templates xquery exist-db
我有一个index.html数据,我通过以下方式包含模板:
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
Run Code Online (Sandbox Code Playgroud)
在索引html网站上我添加了一个关键字搜索表单,我的想法是,当我点击搜索按钮时,它应该调用.xq文件来请求搜索结果:
<form method="GET" action="ksearch.xq">
Run Code Online (Sandbox Code Playgroud)
当我提交表单时,会打开ksearch.xq页面,但即使我包含与上面相同的模板div:
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
Run Code Online (Sandbox Code Playgroud)
ksearch.xq页面没有应用模板.
似乎当我调用.xq文件时,模板未应用,但是当我调用纯HTML文件时,模板将被应用.
所以问题是如何在.xq文件的输出中使用此模板?
提前致谢.
默认情况下,eXist-db的模板框架对具有.html
文件扩展名的文件的请求进行操作,而不是对.xq
文件进行操作.正如您所发现的,模板框架将非.html
文件的结果传递给未更改的文件.(.html
如果controller.xql
在应用程序集合中打开文件,您将看到对文件的特殊处理.)因此,不要ksearch.xq
让您的表单将搜索参数提交给.html
使用模板框架的约定来调用XQuery代码的文件,例如,
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div class="app:show-search-results"/>
</div>
Run Code Online (Sandbox Code Playgroud)
这个app:show-search-results
类(我编写的)将指向app
模块(in /db/apps/myapp/modules/app.xqm
)中名为show-search-results()的函数,其中传统参数在模板函数的其他地方使用.这是您放置搜索XQuery代码的地方.