How to Create a PHP Include in Velocity

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

Est. Read Time: ~Less Than a Minute

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).


#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]” –>


About the Author:

Zedric Myers
Zedric Myers is a Web Designer for Beacon Technologies. After earning his degree in Advertising and Graphic Design, he spent 11 years with an advertising agency in Greensboro, NC where he was initially hired as a designer and transitioned to being a Web Developer.