问题
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">
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">
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">
The ksearch.xq page does not have the template applied.
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.
So the question is how can I use this template also in output of an .xq file?
Thanks in advance.
回答1:
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>
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.
来源:https://stackoverflow.com/questions/21042783/exist-db-include-html-template-in-xq-data