{"id":1633,"date":"2025-04-22T09:30:24","date_gmt":"2025-04-22T13:30:24","guid":{"rendered":"https:\/\/sls.gmu.edu\/web\/?p=1633"},"modified":"2025-04-22T09:30:24","modified_gmt":"2025-04-22T13:30:24","slug":"how-to-create-a-cascade-format-in-velocity-for-a-carousel","status":"publish","type":"post","link":"https:\/\/sls.gmu.edu\/web\/2025\/04\/22\/how-to-create-a-cascade-format-in-velocity-for-a-carousel\/","title":{"rendered":"How to Create a Cascade Format in Velocity for a Carousel"},"content":{"rendered":"<p>This is the context page from template for reference:<\/p>\n<pre><code>&lt;system-data-structure&gt;\r\n  &lt;carousel&gt;yes&lt;\/carousel&gt;\r\n    &lt;slide&gt;\r\n      &lt;image type=\"file\"&gt;\r\n      &lt;content&gt;&lt;\/content&gt;\r\n      &lt;path&gt;\/_images\/paintbrush.jpeg&lt;\/path&gt;\r\n      &lt;link&gt;site:\/\/DEV-Donny\/_images\/paintbrush.jpeg&lt;\/link&gt;\r\n      &lt;site&gt;DEV-Donny&lt;\/site&gt;\r\n      &lt;name&gt;paintbrush.jpeg&lt;\/name&gt;\r\n     &lt;file-size&gt;330352&lt;\/file-size&gt;\r\n     &lt;width&gt;1920&lt;\/width&gt;\r\n     &lt;height&gt;1280&lt;\/height&gt;\r\n     &lt;\/image&gt;\r\n     &lt;heading&gt;Paintbrushes&lt;\/heading&gt;\r\n     &lt;alt&gt;Paintbrushes&lt;\/alt&gt;\r\n   &lt;\/slide&gt;\r\n   &lt;slide&gt;\r\n     &lt;image&gt;\r\n     &lt;path&gt;\/&lt;\/path&gt;\r\n     &lt;\/image&gt;\r\n     &lt;heading\/&gt;\r\n     &lt;alt&gt;&lt;alt\/&gt;\r\n   &lt;\/slide&gt;\r\n   &lt;slide&gt;\r\n     &lt;image type=\"file\"&gt;\r\n     &lt;content&gt;&lt;\/content&gt;\r\n     &lt;path&gt;\/_images\/computer-coffee.jpeg&lt;\/path&gt;\r\n     &lt;link&gt;site:\/\/DEV-Donny\/_images\/computer-coffee.jpeg&lt;\/link&gt;\r\n     &lt;site&gt;DEV-Donny&lt;\/site&gt;\r\n     &lt;name&gt;computer-coffee.jpeg&lt;\/name&gt;\r\n     &lt;file-size&gt;174729&lt;\/file-size&gt;\r\n     &lt;width&gt;1920&lt;\/width&gt;\r\n     &lt;height&gt;1080&lt;\/height&gt;\r\n     &lt;\/image&gt;\r\n     &lt;heading&gt;Computer &amp;amp; Coffee&lt;\/heading&gt;\r\n     &lt;alt&gt;Computer and Coffee&lt;\/alt&gt;\r\n  &lt;\/slide&gt;\r\n  &lt;editor&gt;This is my first page.&lt;\/editor&gt;\r\n&lt;\/system-data-structure&gt;<\/code><\/pre>\n<p>Create Cascade <code>format<\/code> using Velocity:<\/p>\n<pre><code>#set($array = $currentPage.getStructuredDataNodes(\"slide\"))\r\n#set($slides = [])\r\n#foreach($item in $array)\r\n#if($item.getChild(\"image\").asset.path)\r\n#set($dummy = $slides.add($item))\r\n#end\r\n#end\r\n#if($slides.size() &gt; 0 &amp;&amp; $currentPage.getStructuredDataNode(\"carousel\").textValue == \"yes\" )\r\n&lt;header class=\"carousel slide\" id=\"myCarousel\"&gt;\r\n&lt;!-- Indicators --&gt;\r\n&lt;ol class=\"carousel-indicators\"&gt;\r\n#foreach($slide in $slides)\r\n#if($foreach.count == 1)\r\n#set($class = \"active\")\r\n#else \r\n#set($class = \"\")\r\n#end\r\n#set($slideNumber = $foreach.index)\r\n&lt;li class=\"${class}\" data-slide-to=\"${slideNumber}\" data-target=\"#myCarousel\"&gt;&lt;\/li&gt;\r\n#end\r\n&lt;\/ol&gt;\r\n&lt;!-- Wrapper for slides --&gt;\r\n&lt;div class=\"carousel-inner\"&gt;\r\n#foreach($slide in $slides)\r\n#if($foreach.count == 1)\r\n#set($class = \"active\")\r\n#else \r\n#set($class = \"\")\r\n#end\r\n#set($image = $slide.getChild(\"image\").asset.link)\r\n#set($heading = $slide.getChild(\"heading\").textValue)\r\n&lt;div class=\"item ${class}\"&gt;\r\n&lt;div class=\"fill\" style=\"background-image:url('[system-asset]${image}[\/system-asset]');\"&gt;&lt;\/div&gt;\r\n&lt;div class=\"carousel-caption\"&gt;\r\n&lt;h1&gt;$_EscapeTool.xml($heading)&lt;\/h1&gt;\r\n&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n#end\r\n&lt;\/div&gt;\r\n&lt;!-- Controls --&gt;\r\n&lt;a class=\"left carousel-control\" data-slide=\"prev\" href=\"#myCarousel\"&gt;\r\n&lt;span class=\"icon-prev\"&gt;&lt;\/span&gt;\r\n&lt;\/a&gt;\r\n&lt;a class=\"right carousel-control\" data-slide=\"next\" href=\"#myCarousel\"&gt;\r\n&lt;span class=\"icon-next\"&gt;&lt;\/span&gt;\r\n&lt;\/a&gt;\r\n&lt;\/header&gt;\r\n#end<\/code><\/pre>\n<p>This is the transformation result:<\/p>\n<pre><code>#set($array = $currentPage.getStructuredDataNodes(\"slide\"))\r\n#set($slides = [])\r\n#foreach($item in $array)\r\n#if($item.getChild(\"image\").asset.path)\r\n#set($dummy = $slides.add($item))\r\n#end\r\n#end\r\n#if($slides.size() &gt; 0 &amp;&amp; $currentPage.getStructuredDataNode(\"carousel\").textValue == \"yes\" )\r\n&lt;header class=\"carousel slide\" id=\"myCarousel\"&gt;\r\n&lt;!-- Indicators --&gt;\r\n&lt;ol class=\"carousel-indicators\"&gt;\r\n#foreach($slide in $slides)\r\n#if($foreach.count == 1)\r\n#set($class = \"active\")\r\n#else \r\n#set($class = \"\")\r\n#end\r\n#set($slideNumber = $foreach.index)\r\n&lt;li class=\"${class}\" data-slide-to=\"${slideNumber}\" data-target=\"#myCarousel\"&gt;&lt;\/li&gt;\r\n#end\r\n&lt;\/ol&gt;\r\n&lt;!-- Wrapper for slides --&gt;\r\n&lt;div class=\"carousel-inner\"&gt;\r\n#foreach($slide in $slides)\r\n#if($foreach.count == 1)\r\n#set($class = \"active\")\r\n#else \r\n#set($class = \"\")\r\n#end\r\n#set($image = $slide.getChild(\"image\").asset.link)\r\n#set($heading = $slide.getChild(\"heading\").textValue)\r\n&lt;div class=\"item ${class}\"&gt;\r\n&lt;div class=\"fill\" style=\"background-image:url('[system-asset]${image}[\/system-asset]');\"&gt;&lt;\/div&gt;\r\n&lt;div class=\"carousel-caption\"&gt;\r\n&lt;h1&gt;$_EscapeTool.xml($heading)&lt;\/h1&gt;\r\n&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n#end\r\n&lt;\/div&gt;\r\n&lt;!-- Controls --&gt;\r\n&lt;a class=\"left carousel-control\" data-slide=\"prev\" href=\"#myCarousel\"&gt;\r\n&lt;span class=\"icon-prev\"&gt;&lt;\/span&gt;\r\n&lt;\/a&gt;\r\n&lt;a class=\"right carousel-control\" data-slide=\"next\" href=\"#myCarousel\"&gt;\r\n&lt;span class=\"icon-next\"&gt;&lt;\/span&gt;\r\n&lt;\/a&gt;\r\n&lt;\/header&gt;\r\n#end<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is the context page from template for reference: &lt;system-data-structure&gt; &lt;carousel&gt;yes&lt;\/carousel&gt; &lt;slide&gt; &lt;image type=&#8221;file&#8221;&gt; &lt;content&gt;&lt;\/content&gt; &lt;path&gt;\/_images\/paintbrush.jpeg&lt;\/path&gt; &lt;link&gt;site:\/\/DEV-Donny\/_images\/paintbrush.jpeg&lt;\/link&gt; &lt;site&gt;DEV-Donny&lt;\/site&gt; &lt;name&gt;paintbrush.jpeg&lt;\/name&gt; &lt;file-size&gt;330352&lt;\/file-size&gt; &lt;width&gt;1920&lt;\/width&gt; &lt;height&gt;1280&lt;\/height&gt; &lt;\/image&gt; &lt;heading&gt;Paintbrushes&lt;\/heading&gt; &lt;alt&gt;Paintbrushes&lt;\/alt&gt; &lt;\/slide&gt; &lt;slide&gt; &lt;image&gt; &lt;path&gt;\/&lt;\/path&gt; &lt;\/image&gt; &lt;heading\/&gt; &lt;alt&gt;&lt;alt\/&gt; &lt;\/slide&gt; &lt;slide&gt; &lt;image type=&#8221;file&#8221;&gt; &lt;content&gt;&lt;\/content&gt; &lt;path&gt;\/_images\/computer-coffee.jpeg&lt;\/path&gt; &lt;link&gt;site:\/\/DEV-Donny\/_images\/computer-coffee.jpeg&lt;\/link&gt; &lt;site&gt;DEV-Donny&lt;\/site&gt; &lt;name&gt;computer-coffee.jpeg&lt;\/name&gt; &lt;file-size&gt;174729&lt;\/file-size&gt; &lt;width&gt;1920&lt;\/width&gt; &lt;height&gt;1080&lt;\/height&gt; &lt;\/image&gt; &lt;heading&gt;Computer &amp;amp; Coffee&lt;\/heading&gt; &lt;alt&gt;Computer and Coffee&lt;\/alt&gt; &lt;\/slide&gt; &lt;editor&gt;This is my &hellip; <a href=\"https:\/\/sls.gmu.edu\/web\/2025\/04\/22\/how-to-create-a-cascade-format-in-velocity-for-a-carousel\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Create a Cascade Format in Velocity for a Carousel&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[11],"tags":[51],"class_list":["post-1633","post","type-post","status-publish","format-standard","hentry","category-web-development","tag-cascade"],"_links":{"self":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/posts\/1633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/comments?post=1633"}],"version-history":[{"count":0,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/posts\/1633\/revisions"}],"wp:attachment":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/media?parent=1633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/categories?post=1633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/tags?post=1633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}