diff --git a/backend/pdfrender/pagination.go b/backend/pdfrender/pagination.go
index 0193c57..8fd12df 100644
--- a/backend/pdfrender/pagination.go
+++ b/backend/pdfrender/pagination.go
@@ -201,6 +201,10 @@ func (p *Paginator) PaginateMultiList(dataMap map[string]interface{}, templateNa
tracker, exists := listTrackers[trackerKey]
if !exists {
+ // Skip blocks with NOEMPTY flag when they have no data
+ if block.NoEmpty {
+ continue
+ }
// Block has no data, fill with empty items up to MAX
pageData[block.Name] = p.createEmptySliceWithCapacity(block.ListType, block.MaxItems)
continue
@@ -213,9 +217,17 @@ func (p *Paginator) PaginateMultiList(dataMap map[string]interface{}, templateNa
itemsToTake = remaining
}
- // Extract slice for this block and fill to capacity
+ // Skip NOEMPTY blocks when no items remain
+ if block.NoEmpty && itemsToTake == 0 {
+ continue
+ }
+
+ // Extract slice for this block
blockItems := p.extractSlice(tracker.items, tracker.currentIdx, itemsToTake)
+
+ // Always fill to capacity (both normal and NOEMPTY blocks get filled when they have items)
blockItems = p.fillSliceToCapacity(blockItems, block.MaxItems)
+
pageData[block.Name] = blockItems
tracker.currentIdx += itemsToTake
}
diff --git a/backend/pdfrender/template_metadata.go b/backend/pdfrender/template_metadata.go
index d6b9296..a876180 100644
--- a/backend/pdfrender/template_metadata.go
+++ b/backend/pdfrender/template_metadata.go
@@ -20,6 +20,7 @@ type BlockMetadata struct {
MaxItems int // Maximum number of items this block can display
Filter string // Optional filter criteria (e.g., "learned", "unlearned", "languages")
Column int // Column number for multi-column layouts (0 if single column)
+ NoEmpty bool // If true, remove this block when it contains no items
}
// TemplateSet contains all templates and their metadata for a format
diff --git a/backend/pdfrender/template_parser.go b/backend/pdfrender/template_parser.go
index c65515c..5990ba9 100644
--- a/backend/pdfrender/template_parser.go
+++ b/backend/pdfrender/template_parser.go
@@ -7,33 +7,63 @@ import (
)
// ParseTemplateMetadata extracts block metadata from HTML comments in template content
-// Format:
+// Format:
func ParseTemplateMetadata(templateContent string) []BlockMetadata {
blocks := []BlockMetadata{}
- // Regex to match:
- re := regexp.MustCompile(``)
+ // Simple regex to find all BLOCK comments
+ re := regexp.MustCompile(``)
matches := re.FindAllStringSubmatch(templateContent, -1)
for _, match := range matches {
- if len(match) < 4 {
+ if len(match) < 2 {
continue
}
- name := strings.TrimSpace(match[1])
- listType := strings.TrimSpace(match[2])
- maxItems, _ := strconv.Atoi(strings.TrimSpace(match[3]))
+ // Parse the content of the BLOCK comment
+ blockContent := match[1]
- filter := ""
- if len(match) > 4 && match[4] != "" {
- filter = strings.TrimSpace(match[4])
+ // Extract BLOCK name
+ nameRe := regexp.MustCompile(`BLOCK:\s*([^,]+)`)
+ if !nameRe.MatchString(match[0]) {
+ continue
}
+ nameMatch := nameRe.FindStringSubmatch(match[0])
+ name := strings.TrimSpace(nameMatch[1])
+
+ // Extract TYPE
+ typeRe := regexp.MustCompile(`TYPE:\s*([^,]+)`)
+ typeMatch := typeRe.FindStringSubmatch(blockContent)
+ if typeMatch == nil {
+ continue
+ }
+ listType := strings.TrimSpace(typeMatch[1])
+
+ // Extract MAX
+ maxRe := regexp.MustCompile(`MAX:\s*(\d+)`)
+ maxMatch := maxRe.FindStringSubmatch(blockContent)
+ if maxMatch == nil {
+ continue
+ }
+ maxItems, _ := strconv.Atoi(strings.TrimSpace(maxMatch[1]))
+
+ // Extract FILTER (optional)
+ filter := ""
+ filterRe := regexp.MustCompile(`FILTER:\s*([^,]+)`)
+ filterMatch := filterRe.FindStringSubmatch(blockContent)
+ if filterMatch != nil {
+ filter = strings.TrimSpace(filterMatch[1])
+ }
+
+ // Check for NOEMPTY flag (optional)
+ noEmpty := strings.Contains(blockContent, "NOEMPTY")
blocks = append(blocks, BlockMetadata{
Name: name,
ListType: listType,
MaxItems: maxItems,
Filter: filter,
+ NoEmpty: noEmpty,
})
}
diff --git a/backend/templates/Default_A4_Quer/page_2.2.html b/backend/templates/Default_A4_Quer/page_2.2.html
index 639442e..411bdaf 100644
--- a/backend/templates/Default_A4_Quer/page_2.2.html
+++ b/backend/templates/Default_A4_Quer/page_2.2.html
@@ -37,17 +37,32 @@
| {{.Name}}{{if .Bemerkung}}:{{.Bemerkung}}{{end}} | {{if .Value}}+ {{.Value}}{{else}} {{end}} | {{if .PracticePoints}}{{.PracticePoints}}{{end}} |
{{end}}
-
-
-
- | Fertigkeit |
- EW |
- PP |
-
- {{range .SkillsLanguage}}
- | {{.Name}}{{if .Bemerkung}}:{{.Bemerkung}}{{end}} | {{if .Value}}+ {{.Value}}{{else}} {{end}} | {{if .PracticePoints}}{{.PracticePoints}}{{end}} |
- {{end}}
-
+
+
+ {{if .SkillsLanguage}}{{if (index .SkillsLanguage 0).Name}}
+
+
+ | Fertigkeit |
+ EW |
+ PP |
+
+ {{range .SkillsLanguage}}
+ | {{.Name}}{{if .Bemerkung}}:{{.Bemerkung}}{{end}} | {{if .Value}}+ {{.Value}}{{else}} {{end}} | {{if .PracticePoints}}{{.PracticePoints}}{{end}} |
+ {{end}}
+
+ {{end}}{{end}}
+
+
+
+ | Fertigkeit |
+ EW |
+ PP |
+
+ {{range .SkillsLearned}}
+ | {{.Name}}{{if .Bemerkung}}:{{.Bemerkung}}{{end}} | {{if .Value}}+ {{.Value}}{{else}} {{end}} | {{if .PracticePoints}}{{.PracticePoints}}{{end}} |
+ {{end}}
+
+