2 06, 2014

Adding Velocity Foreach Conditionals

By | 2017-06-16T13:14:07+00:00 June 2nd, 2014|Categories: Cascade CMS|Tags: , , , , , , |

There are different approaches to adding conditionals in a foreach loop. These are just a few code examples that are simple and easy to integrate in Velocity.

Note the examples would are what go in the foreach loop. Your set would be applied above with your specific variables.

Example 1: Gets the last value in the foreach loop and applying HTML or code element.

#if ( $foreach.count == $group.size() )

HTML can be placed here.

#end

Example 2: Gets any value except that last one in the foreach loop and applying HTML or code element.

#if ( $foreach.count != $foreachGroup.size() )

HTML can be placed here.

#end

Example 3: Gets any value with a specific count and then uses #break. (Note: #break in a foreach loop is available in version 1.6 or higher)

#if ( $foreach.count > 3 )

#break

#end

15 05, 2014

How to Create a PHP Include in Velocity

By | 2017-06-16T12:46:56+00:00 May 15th, 2014|Categories: Web Development|Tags: , , , |

If you work with Velocity and need to add a PHP include, there is a simple way. As you know the hash tag is the main character before a directive or code comment. So you can’t use it for regular text or inline copy if it’s within the velocity code itself.

The way to get around it is to create a variable. When processing it adds the needed hash tag for the PHP include and can successfully preview the include file in the web browser(s).

Example:

#set($pages = $_XPathTool.selectNodes($contentRoot, “/system-index-block/system-page”))

#foreach($page in $pages)

#set ( $hash = ‘#’ )

#set ($path = $page.getChild(“path”).value)

<!– #[[#include]]# file=”[system-asset]${path}[/system-asset]” –>

#end