Feature: allow overriding parts of TEMPLATE_DIR #6

Open
opened 2025-04-18 15:52:20 +02:00 by tom · 1 comment

Rather than modifying the core, or copying it all, allow overriding individual templates by placing them in the project folder e.g. $SRC_DIR/../templates

This allows the footer to be very easily replaced.

diff --git a/scripts/build/templates.sh b/scripts/build/templates.sh
index cb4a375..ff56fc2 100755
--- a/scripts/build/templates.sh
+++ b/scripts/build/templates.sh
@@ -92,7 +92,13 @@ preload_templates() {
     for tmpl in "${templates_to_load[@]}"; do
         if [ -f "$template_dir/$tmpl" ]; then
             local content
-            content=$(load_template "$template_dir/$tmpl" "$tmpl")
+
+            if [ -f "${SRC_DIR}/../templates/$tmpl" ]; then
+                content=$(load_template "${SRC_DIR}/../templates/$tmpl" "$tmpl")
+                echo -e "$YELLOW Using override for $tmpl"
+            else
+                content=$(load_template "$template_dir/$tmpl" "$tmpl")
+            fi
 
             # Store the template in the appropriate global variable
             case "$tmpl" in

Rather than modifying the core, or copying it all, allow overriding individual templates by placing them in the project folder e.g. `$SRC_DIR/../templates` This allows the footer to be very easily replaced. ``` diff --git a/scripts/build/templates.sh b/scripts/build/templates.sh index cb4a375..ff56fc2 100755 --- a/scripts/build/templates.sh +++ b/scripts/build/templates.sh @@ -92,7 +92,13 @@ preload_templates() { for tmpl in "${templates_to_load[@]}"; do if [ -f "$template_dir/$tmpl" ]; then local content - content=$(load_template "$template_dir/$tmpl" "$tmpl") + + if [ -f "${SRC_DIR}/../templates/$tmpl" ]; then + content=$(load_template "${SRC_DIR}/../templates/$tmpl" "$tmpl") + echo -e "$YELLOW Using override for $tmpl" + else + content=$(load_template "$template_dir/$tmpl" "$tmpl") + fi # Store the template in the appropriate global variable case "$tmpl" in ```
Owner

@tom wrote in #6 (comment):

Rather than modifying the core, or copying it all, allow overriding individual templates by placing them in the project folder e.g. $SRC_DIR/../templates

This allows the footer to be very easily replaced.

diff --git a/scripts/build/templates.sh b/scripts/build/templates.sh
index cb4a375..ff56fc2 100755
--- a/scripts/build/templates.sh
+++ b/scripts/build/templates.sh
@@ -92,7 +92,13 @@ preload_templates() {
     for tmpl in "${templates_to_load[@]}"; do
         if [ -f "$template_dir/$tmpl" ]; then
             local content
-            content=$(load_template "$template_dir/$tmpl" "$tmpl")
+
+            if [ -f "${SRC_DIR}/../templates/$tmpl" ]; then
+                content=$(load_template "${SRC_DIR}/../templates/$tmpl" "$tmpl")
+                echo -e "$YELLOW Using override for $tmpl"
+            else
+                content=$(load_template "$template_dir/$tmpl" "$tmpl")
+            fi
 
             # Store the template in the appropriate global variable
             case "$tmpl" in

I'll think about it. Thank you!

@tom wrote in https://brew.bsd.cafe/stefano/BSSG/issues/6#issue-60: > Rather than modifying the core, or copying it all, allow overriding individual templates by placing them in the project folder e.g. `$SRC_DIR/../templates` > > This allows the footer to be very easily replaced. > > ```text > diff --git a/scripts/build/templates.sh b/scripts/build/templates.sh > index cb4a375..ff56fc2 100755 > --- a/scripts/build/templates.sh > +++ b/scripts/build/templates.sh > @@ -92,7 +92,13 @@ preload_templates() { > for tmpl in "${templates_to_load[@]}"; do > if [ -f "$template_dir/$tmpl" ]; then > local content > - content=$(load_template "$template_dir/$tmpl" "$tmpl") > + > + if [ -f "${SRC_DIR}/../templates/$tmpl" ]; then > + content=$(load_template "${SRC_DIR}/../templates/$tmpl" "$tmpl") > + echo -e "$YELLOW Using override for $tmpl" > + else > + content=$(load_template "$template_dir/$tmpl" "$tmpl") > + fi > > # Store the template in the appropriate global variable > case "$tmpl" in > ``` I'll think about it. Thank you!
stefano self-assigned this 2025-04-23 10:20:05 +02:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: stefano/BSSG#6
No description provided.