diff --git a/v2/README.md b/v2/README.md
index 430eed1..0041b1b 100644
--- a/v2/README.md
+++ b/v2/README.md
@@ -33,6 +33,10 @@ Some improvements to check, later:
Version Changes Control
=======================
+v2.1.4 - 2023-05-17
+-----------------------
+- Bug corrected on @@ loops subtemplates, the .none template was not reach when the array is set but empty
+
v2.1.3 - 2022-09-02
-----------------------
- Bug corrected on XDataset.GetString() and XDatasetCollection.GetDataString().
diff --git a/v2/xcore.go b/v2/xcore.go
index 950159e..14ba057 100644
--- a/v2/xcore.go
+++ b/v2/xcore.go
@@ -868,7 +868,7 @@
package xcore
// VERSION is the used version nombre of the XCore library.
-const VERSION = "2.1.3"
+const VERSION = "2.1.4"
// LOG is the flag to activate logging on the library.
// if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters.
diff --git a/v2/xtemplate.go b/v2/xtemplate.go
index 72994fd..8d806ef 100644
--- a/v2/xtemplate.go
+++ b/v2/xtemplate.go
@@ -375,7 +375,7 @@ func (t *XTemplate) injector(datacol XDatasetCollectionDef, language *XLanguage)
if subt != nil {
if datacol != nil {
cl, _ := datacol.GetCollection(subdataid)
- if cl != nil {
+ if cl != nil && cl.Count() > 0 {
for i := 0; i < cl.Count(); i++ {
var tmp *XTemplate
tmp = t.GetTemplate(subtemplateid + ".key." + strconv.Itoa(i))
diff --git a/v2/xtemplate_test.go b/v2/xtemplate_test.go
index 4ad1dfe..8143177 100644
--- a/v2/xtemplate_test.go
+++ b/v2/xtemplate_test.go
@@ -41,6 +41,34 @@ I love {{name}}
// I love Videogames
}
+func ExampleNewXTemplateEmptyLoop() {
+ tmpl, _ := NewXTemplateFromString(`
+%-- This is a comment. It will not appear in the final code. --%
+Let's put your name here: {{clientname}}
+And lets put your hobbies here:
+%-- note the 1rst id is the entry into the data to inject and the second one is the name of the sub-template to use --%
+@@hobbies@@
+%-- And you need the template for each hobby:--%
+[[hobbies]]
+I love {{name}}
+[[]]
+[[hobbies.none]]
+I love nothing
+[[]]
+`)
+ // The creation of the data is obviously tedious here, in real life it should come from a JSON, a Database, etc
+ data := XDataset{
+ "clientname": "Fred",
+ "hobbies": &XDatasetCollection{},
+ }
+
+ fmt.Println(tmpl.Execute(&data))
+ // Output:
+ // Let's put your name here: Fred
+ // And lets put your hobbies here:
+ // I love nothing
+}
+
func TestNewXTemplateFromString(t *testing.T) {
tmpl, _ := NewXTemplateFromString(`
%-- This is a comment. It will not appear in the final code. --%