friends) {
+ this.friends = friends;
+ }
+
+ public static class Address {
+
+ private String street;
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+ }
+
+}
diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java
new file mode 100644
index 0000000000..36f78f486e
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java
@@ -0,0 +1,49 @@
+package com.baeldung.handlebars;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.github.jknack.handlebars.Handlebars;
+import com.github.jknack.handlebars.Template;
+import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
+import com.github.jknack.handlebars.io.TemplateLoader;
+import java.io.IOException;
+import org.junit.Test;
+
+/**
+ * Showcases reusing the existing templates.
+ *
+ * @author isaolmez
+ */
+public class ReusingTemplatesUnitTest {
+
+ private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html");
+
+ @Test
+ public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException {
+ Handlebars handlebars = new Handlebars(templateLoader);
+ Template template = handlebars.compile("page");
+ Person person = new Person();
+ person.setName("Baeldung");
+
+ String templateString = template.apply(person);
+
+ assertThat(templateString).isEqualTo("Hi Baeldung!
\nThis is the page Baeldung
");
+ }
+
+ @Test
+ public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException {
+ Handlebars handlebars = new Handlebars(templateLoader);
+ Template template = handlebars.compile("simplemessage");
+ Person person = new Person();
+ person.setName("Baeldung");
+
+ String templateString = template.apply(person);
+
+ assertThat(templateString).isEqualTo("\n\n"
+ + "\n"
+ + "\n This is the intro\n\n"
+ + "\n Hi there!\n\n"
+ + "\n"
+ + "");
+ }
+}
diff --git a/libraries-2/src/test/resources/greeting.hbs b/libraries-2/src/test/resources/greeting.hbs
new file mode 100644
index 0000000000..71a8266bce
--- /dev/null
+++ b/libraries-2/src/test/resources/greeting.hbs
@@ -0,0 +1 @@
+Hi {{name}}!
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/each.html b/libraries-2/src/test/resources/handlebars/each.html
new file mode 100644
index 0000000000..1570311bfc
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/each.html
@@ -0,0 +1,3 @@
+{{#each friends}}
+{{name}} is my friend.
+{{/each}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/each_mustache.html b/libraries-2/src/test/resources/handlebars/each_mustache.html
new file mode 100644
index 0000000000..1570311bfc
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/each_mustache.html
@@ -0,0 +1,3 @@
+{{#each friends}}
+{{name}} is my friend.
+{{/each}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/greeting.html b/libraries-2/src/test/resources/handlebars/greeting.html
new file mode 100644
index 0000000000..71a8266bce
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/greeting.html
@@ -0,0 +1 @@
+Hi {{name}}!
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/header.html b/libraries-2/src/test/resources/handlebars/header.html
new file mode 100644
index 0000000000..80cca699e4
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/header.html
@@ -0,0 +1 @@
+Hi {{name}}!
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/if.html b/libraries-2/src/test/resources/handlebars/if.html
new file mode 100644
index 0000000000..ebdc724f66
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/if.html
@@ -0,0 +1,5 @@
+{{#if busy}}
+{{name}} is busy.
+{{else}}
+{{name}} is not busy.
+{{/if}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/if_mustache.html b/libraries-2/src/test/resources/handlebars/if_mustache.html
new file mode 100644
index 0000000000..d75f5fa8f9
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/if_mustache.html
@@ -0,0 +1,5 @@
+{{#if busy}}
+{{name}} is busy.
+{{^}}
+{{name}} is not busy.
+{{/if}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/messagebase.html b/libraries-2/src/test/resources/handlebars/messagebase.html
new file mode 100644
index 0000000000..7ee3257e06
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/messagebase.html
@@ -0,0 +1,9 @@
+
+
+{{#block "intro"}}
+ This is the intro
+{{/block}}
+{{#block "message"}}
+{{/block}}
+
+
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/page.html b/libraries-2/src/test/resources/handlebars/page.html
new file mode 100644
index 0000000000..27b20737f3
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/page.html
@@ -0,0 +1,2 @@
+{{>header}}
+This is the page {{name}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/person.html b/libraries-2/src/test/resources/handlebars/person.html
new file mode 100644
index 0000000000..9df7850f60
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/person.html
@@ -0,0 +1 @@
+{{#isBusy this}}{{/isBusy}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/simplemessage.html b/libraries-2/src/test/resources/handlebars/simplemessage.html
new file mode 100644
index 0000000000..3b3a01980a
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/simplemessage.html
@@ -0,0 +1,4 @@
+{{#partial "message" }}
+ Hi there!
+{{/partial}}
+{{> messagebase}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/with.html b/libraries-2/src/test/resources/handlebars/with.html
new file mode 100644
index 0000000000..90077b4835
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/with.html
@@ -0,0 +1,3 @@
+{{#with address}}
+I live in {{street}}
+{{/with}}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/handlebars/with_mustache.html b/libraries-2/src/test/resources/handlebars/with_mustache.html
new file mode 100644
index 0000000000..3adf6a7556
--- /dev/null
+++ b/libraries-2/src/test/resources/handlebars/with_mustache.html
@@ -0,0 +1,3 @@
+{{#address}}
+I live in {{street}}
+{{/address}}
\ No newline at end of file