Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 复合模板页面_Clojure_Compojure - Fatal编程技术网

Clojure 复合模板页面

Clojure 复合模板页面,clojure,compojure,Clojure,Compojure,我有一堆共享相同页眉和页脚的静态html文件。我 希望在所有页面上共享此页眉和页脚。现在我 使用以下路径,但它有点难看,我必须处理所有特殊情况。有没有像php的include函数这样的简单方法 (卸载我的应用程序) (获取“/” (带模板的html) “main.header”“index.body”“main.footer”)) (获取“/*.html” (带模板的html) “main.header”(str(参数:“.body”)“main.footer”)) (获取“//” (带模板的

我有一堆共享相同页眉和页脚的静态html文件。我 希望在所有页面上共享此页眉和页脚。现在我 使用以下路径,但它有点难看,我必须处理所有特殊情况。有没有像php的include函数这样的简单方法


(卸载我的应用程序)
(获取“/”
(带模板的html)
“main.header”“index.body”“main.footer”))
(获取“/*.html”
(带模板的html)
“main.header”(str(参数:“.body”)“main.footer”))
(获取“//”
(带模板的html)
(str(参数:“/folder.header”)
(str(参数:“/index.body”)
(str(参数:“/folder.footer”))
(获取“/”
(或(服务文件(参数:):下一个))
(任何“*”
(未找到页面)))

从我所读到的关于Compojure的内容来看,我认为它不像PHP那样对响应体的“自动前置”和“自动附加”的概念有内在的支持

我有经验的其他web框架将这一职责委托给了它们的模板引擎,而PHP有点模糊了这一点。它们允许您在此处显式地“包含”一个公共片段,或呈现一个宏,甚至通过基本的继承形式(此模板扩展了该模板)来实现这一点

基本上,无论HTML是静态的还是动态的,模板引擎都允许您进行模块化,以获得更好的可维护性

这就是说,Compojure似乎没有一个完整的HTML模板引擎捆绑在一起。它确实有一个很好的HTML/XML域特定语言(DSL),但我认为您需要的是一个可以与Compojure一起使用的一流模板引擎

似乎是Clojure启发的模板引擎,获得了最多的点击率,但我相信还有其他的。考虑到Clojure的JVM集成,您可能也可以从任何一个方面进行选择


根据您选择的选项,可能需要编写几行粘合代码才能将模板加载、呈现并流式传输到Compojure HTTP响应中,但您只需编写一次,然后在任何地方重复使用。

例如前两条路由/和/*.html,它们都路由到index.html,但我必须保留两条路由。

(defroutes my-app
  (GET "/" 
    (html-with-template 
     "main.header"  "index.body" "main.footer" ))
  (GET "/*.html" 
    (html-with-template 
     "main.header" (str (params :*) ".body") "main.footer" ))
  (GET "/*/" 
    (html-with-template 
     (str (params :*) "/folder.header") 
     (str (params :*) "/index.body")
     (str (params :*) "/folder.footer")))
  (GET "/*" 
    (or (serve-file (params :*)) :next))
  (ANY "*"
    (page-not-found)))