【问题标题】:eXist-db include html template in .xq dataeXist-db 在 .xq 数据中包含 html 模板
【发布时间】:2014-01-29 08:03:21
【问题描述】:

我有一个 index.html 数据,我通过以下方式包含了模板:

<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">

在 index html 网站上,我包含了一个关键字搜索表单,其想法是当我单击搜索按钮时,它应该调用一个 .xq 文件来请求搜索结果:

<form method="GET" action="ksearch.xq">

当我提交表单时,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">

ksearch.xq 页面没有应用模板。

似乎当我调用 .xq 文件时没有应用模板,但是当我调用纯 HTML 文件时,应用了模板。

所以问题是如何在 .xq 文件的输出中也使用此模板?

提前致谢。

【问题讨论】:

    标签: html templates xquery exist-db


    【解决方案1】:

    默认情况下,eXist-db 的模板框架对带有.html 文件扩展名的文件的请求进行操作,而不是对.xq 文件的请求。如您所见,模板框架将来自非.html 文件的结果原封不动地传递。 (如果您在应用程序的集合中打开 controller.xql 文件,您将看到对 .html 文件的特殊处理。)因此,不是 ksearch.xq,而是让您的表单将搜索参数提交到使用模板框架调用 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>
    

    这个app:show-search-results 类(我编造的)将指向app 模块(在/db/apps/myapp/modules/app.xqm 中)中称为show-search-results() 的函数,使用模板中其他地方使用的常规参数职能。这是您放置搜索 XQuery 代码的地方。

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 2017-03-12
      • 2017-10-07
      • 1970-01-01
      • 2015-08-31
      相关资源
      最近更新 更多