eXist-db在.xq数据中包含html模板 [英] eXist-db include html template in .xq data
问题描述
我有一个index.html数据,其中通过以下方式包含了模板:
i have an index.html data where I included the template through:
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
在索引html站点上,我包括了一个关键字搜索表单,其思想是,当我单击搜索按钮时,它应该调用一个.xq文件来请求搜索结果:
At the index html site I included a keyword search form, and the idea is when I click on the search button it should call an .xq file to request the search results:
<form method="GET" action="ksearch.xq">
提交表单时,ksearch.xq页面会打开,即使我包含与上面相同的模板div:
When I submit the form, the ksearch.xq page opens, but even though I include the same template div as above:
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
ksearch.xq页面未应用模板.
The ksearch.xq page does not have the template applied.
当我调用.xq文件时,似乎没有应用模板,但是当我调用纯HTML文件时,则应用了模板.
It seems that when I call an .xq file the template is not applied, but when I call a plain HTML file, the template is applied.
所以问题是,如何在.xq文件的输出中也使用此模板?
So the question is how can I use this template also in output of an .xq file?
谢谢.
推荐答案
eXist-db的模板框架默认情况下对具有.html
文件扩展名的文件(而不是.xq
文件)的请求起作用.如您所见,模板框架将非.html
文件中的结果通过不变的形式传递. (如果打开应用程序集合中的controller.xql
文件,您将看到.html
文件的特殊处理.)因此,让表单将搜索参数提交给使用该文件的.html
文件而不是ksearch.xq
.模板框架的约定以调用XQuery代码,例如
eXist-db's templating framework, by default, operates on requests for files with the .html
file extension, not for .xq
files. As you have found, the templating framework passes results from non-.html
files through unchanged. (You will see the special handling for .html
files if you open the controller.xql
file in the app's collection.) Thus, instead of ksearch.xq
, have your form submit the search parameters to an .html
file that uses the templating framework's conventions to call XQuery code, e.g.,
<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>
此app:show-search-results
类(由我组成)将指向app
模块(在/db/apps/myapp/modules/app.xqm
中)中的一个名为show-search-results()的函数,其常规参数如模板中的其他地方所用.功能.在这里放置搜索XQuery代码.
This app:show-search-results
class (which I made-up) would point to a function in the app
module (in /db/apps/myapp/modules/app.xqm
) called show-search-results(), with the conventional arguments as used elsewhere in template functions. This is where you would put your search XQuery code.
这篇关于eXist-db在.xq数据中包含html模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!