package main // getString extracts a string value from a content map. func getString(content map[string]any, key string) string { if v, ok := content[key].(string); ok { return v } return "" } // getStringWithDefault returns the string at key or the default when absent/empty. func getStringWithDefault(content map[string]any, key, def string) string { if v := getString(content, key); v != "" { return v } return def } // getBool extracts a bool value from a content map. Accepts true/false and // string forms "true"/"false"/"yes"/"no"/"1"/"0" (admin select dropdowns // commonly store booleans as strings). func getBool(content map[string]any, key string, def bool) bool { if v, ok := content[key].(bool); ok { return v } if v, ok := content[key].(string); ok { switch v { case "true", "yes", "1": return true case "false", "no", "0": return false } } return def } // getSlice extracts a slice of map values from content[key]. JSON decoding // gives []any; we narrow to []map[string]any so block code can index into // individual items by name. func getSlice(content map[string]any, key string) []map[string]any { if v, ok := content[key].([]any); ok { result := make([]map[string]any, 0, len(v)) for _, item := range v { if m, ok := item.(map[string]any); ok { result = append(result, m) } } return result } return nil }