{"id":5949,"date":"2018-02-27T21:01:46","date_gmt":"2018-02-27T21:01:46","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=5949"},"modified":"2018-02-27T21:01:46","modified_gmt":"2018-02-27T21:01:46","slug":"embedding-files-and-or-templates-within-templates-using-velcocity","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/embedding-files-and-or-templates-within-templates-using-velcocity\/","title":{"rendered":"Embedding files and\/or templates within templates using Velcocity"},"content":{"rendered":"<p>We can embed a file or other templates within Velocity templates &#8211; this is obviously useful for reusing snippets of code\/text or whatever in more than file. We still need to create the context mappings for all the template file that form out overall template &#8211; in other words we supply the mappings the container template and all of the embedded templates.<\/p>\n<p>To embed a template we simply use the #include or #parse directives. #include is used to pull in a template or file without transforming it using the template engine, i.e. any variables etc. will <strong>not<\/strong> be transformed or rendered by Velocity whereas #parse will transform any Velocity variables or code.<\/p>\n<p>Taking the template <em>(template.txt.vm)<\/em> from my previous post, which looked like this<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nHello $name,\r\n\r\nThis is a $template_name template.\r\n<\/pre>\n<p>we might break this template into the following two templates<\/p>\n<p><em>salutation.txt.vm<\/em><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nHello $name,\r\n\r\n<\/pre>\n<p>and <em>template.txt.vm<\/em> becomes<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n#parse(&quot;templates\/salutation.txt.vm&quot;)\r\n\r\nThis is a $template_name template.\r\n<\/pre>\n<p>This will result in the combined and transformed template.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can embed a file or other templates within Velocity templates &#8211; this is obviously useful for reusing snippets of code\/text or whatever in more than file. We still need to create the context mappings for all the template file that form out overall template &#8211; in other words we supply the mappings the container [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[161,204],"tags":[],"class_list":["post-5949","post","type-post","status-publish","format-standard","hentry","category-java","category-velocity"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=5949"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5949\/revisions"}],"predecessor-version":[{"id":5955,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5949\/revisions\/5955"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=5949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=5949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=5949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}