Projekt-Seite erstellt: Velocity-Template - JSON über th:with weitergereicht
authorKai Moritz <kai@juplo.de>
Fri, 8 Jul 2016 16:31:26 +0000 (18:31 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 12 May 2017 21:54:39 +0000 (23:54 +0200)
Da die definierten Variablen sonst erst zu spät zur Verfügung stehen, müssen
sie per th:with in das Layout-Template hereingereicht und dort mit
juplo:variables verarbeitet werden.

src/site/site.xml
src/site/template.vm

index ce59948..c89b14c 100644 (file)
@@ -12,7 +12,7 @@
   <custom>
     <thymeproxy>
       <path>/simple-mapper/</path>
-      <crumbs>{"uri":"/projects.html","name":"Projects"},{"uri":"/simple-mapper/index.html","name":"Simple Mapper 4 JSON"}</crumbs>
+      <crumbs>{&amp;quot;uri&amp;quot;:&amp;quot;/projects.html&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Projects&amp;quot;},{&amp;quot;uri&amp;quot;:&amp;quot;/simple-mapper/index.html&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Simple Mapper 4 JSON&amp;quot;}</crumbs>
     </thymeproxy>
   </custom>
 </project>
index a507db2..003c8d2 100644 (file)
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:layout="http://www.thymeleaf.org"
     layout:decorator="templates/layout"
-    th:with="uri='$sitePath$alignedFileName'"
+    th:with="
+      uri='$sitePath$alignedFileName',
+      json='merge:{&quot;pages&quot;:{#set($sep = "")#foreach($page in $pages)$sep&quot;$sitePath$page.uri&quot;:{&quot;name&quot;:&quot;$page.name&quot;,#if(!$page.childs.isEmpty())&quot;childs&quot;:{#set($csep = "")#foreach($child in $page.childs.entrySet())$csep&quot;$sitePath$child.key&quot;:&quot;$child.value&quot;#set($csep = ",")#end},#end&quot;crumbs&quot;:[#set($csep = "")#if($siteCrumbs)$siteCrumbs#set($csep = ",")#end#foreach($crumb in $page.crumbs)$csep{&quot;uri&quot;:&quot;$sitePath$crumb.uri&quot;,&quot;name&quot;:&quot;$crumb.name&quot;}#set($csep = ",")#end]#if($page.title),&quot;title&quot;:&quot;$page.title&quot;#end#if($page.alt),&quot;alt&quot;:&quot;$page.alt&quot;#end#if($page.img),&quot;img&quot;:&quot;$page.img&quot;#end}#set($sep = ",")#end}#if($siteTitle),&quot;site_title&quot;:&quot;$siteTitle&quot;#end#if($siteAlt),&quot;site_alt&quot;:&quot;$siteAlt&quot;#end#if($siteImg),&quot;site_img&quot;:&quot;$siteImg&quot;#end}'
+      "
     >
   <head>
     <title>juplo - $title</title>
       </ol>
     </p>
     <hr />
-    <article class="main" layout:fragment="maincontent" juplo:variables='merge:{"pages":{#set($sep = "")#foreach($page in $pages)$sep"$sitePath$page.uri":{"name":"$page.name",#if(!$page.childs.isEmpty())"childs":{#set($csep = "")#foreach($child in $page.childs.entrySet())$csep"$sitePath$child.key":"$child.value"#set($csep = ",")#end},#end"crumbs":[#set($csep = "")#if($siteCrumbs)$siteCrumbs#set($csep = ",")#end#foreach($crumb in $page.crumbs)$csep{"uri":"$sitePath$crumb.uri","name":"$crumb.name"}#set($csep = ",")#end]#if($page.title),"title":"$page.title"#end#if($page.alt),"alt":"$page.alt"#end#if($page.img),"img":"$page.img"#end}#set($sep = ",")#end}#if($siteTitle),"site_title":"$siteTitle"#end#if($siteAlt),"site_alt":"$siteAlt"#end#if($siteImg),"site_img":"$siteImg"#end}'>
+    <article class="main" layout:fragment="maincontent">
       <header><h1>$shortTitle</h1></header>
       $bodyContent
     </article>