From 98211433ed762ebb7007960549fecd0b4bf9bfa5 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 26 Feb 2021 21:01:54 +0000 Subject: [PATCH] FIX: Allow SS4 includes without full path (fixes #6) --- .../silverstripe/util/SilverstripeFileUtil.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/kinglozzer/silverstripe/util/SilverstripeFileUtil.java b/src/main/java/com/kinglozzer/silverstripe/util/SilverstripeFileUtil.java index 2720e37..a8fe424 100644 --- a/src/main/java/com/kinglozzer/silverstripe/util/SilverstripeFileUtil.java +++ b/src/main/java/com/kinglozzer/silverstripe/util/SilverstripeFileUtil.java @@ -36,9 +36,18 @@ public static List findIncludeTemplate(Project project, Str String templatePath = templatePathFragments[1]; // In SS4, we have to make sure the entire path matches. In SS3, just the file name matching is enough + // Special case - "Includes" directory at any level if (SilverstripeVersionUtil.isSilverstripe4OrMore(project)) { if (templatePath.equals(key)) { result.add(file); + } else { + // In SS4, <% include Foo %> should still match "templates/Includes/Foo.ss" without including + // the full path - so we manually inject "Includes/" and check again + int lastSlash = key.lastIndexOf("/"); + String includeKey = key.substring(0, lastSlash) + "/Includes/" + key.substring(lastSlash + 1); + if (templatePath.equals(includeKey)) { + result.add(file); + } } } else if (templatePath.endsWith(key)) { result.add(file);