From 96b724c9b10ef69dee594f6f725c0412cdf70f19 Mon Sep 17 00:00:00 2001
From: Jake <j.vondoemming@stud.uni-goettingen.de>
Date: Mon, 1 Aug 2022 22:34:06 +0200
Subject: [PATCH] added getters.html

---
 theme/templates/macros/getters.html | 53 +++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 theme/templates/macros/getters.html

diff --git a/theme/templates/macros/getters.html b/theme/templates/macros/getters.html
new file mode 100644
index 0000000..6e9313a
--- /dev/null
+++ b/theme/templates/macros/getters.html
@@ -0,0 +1,53 @@
+{%- macro category_by_name(catname, ignore_native = False) -%}
+	{%- if ignore_native -%}
+		{{- caller(null, sc.categories[catname], null) -}}
+	{%- else -%}
+		{%- for nativecat, catarticles in categories -%}
+			{%- if nativecat.name == catname -%}
+				{{- caller(nativecat, sc.categories[catname], catarticles) -}}
+			{%- endif -%}
+		{%- endfor -%}
+	{%- endif -%}
+{%- endmacro -%}
+
+{%- macro tag_by_name(tagname) -%}
+	{%- for nativetag, tagarticles in tags -%}
+		{%- if nativetag.name == tagname -%}
+			{%- if tagname in sc.categories -%}
+				{{- caller(nativetag, sc.categories[tagname], tagarticles) -}}
+			{%- else -%}
+				{{- caller(nativetag, None, tagarticles) -}}
+			{%- endif -%}
+		{%- endif -%}
+	{%- endfor -%}
+{%- endmacro -%}
+
+{%- macro article_by_slug(slug, lang) -%}
+	{%- for a in all_articles -%}
+		{%- if a.slug == slug and a.lang == lang -%}
+			{{- caller(a) -}}
+		{%- endif -%}
+	{%- endfor -%}
+{%- endmacro -%}
+
+{%- macro page_by_slug(slug, lang) -%}
+	{%- for p in pages -%}
+		{%- if p.slug == slug and p.lang == lang -%}
+			{{- caller(p) -}}
+		{%- endif -%}
+	{%- endfor -%}
+{%- endmacro -%}
+
+{%- macro article_or_page_by_slug(slug, lang) -%}
+	{%- for a in all_articles -%}
+		{%- if a.slug == slug and a.lang == lang -%}
+			{{- caller(a, "article") -}}
+		{%- endif -%}
+	{%- endfor -%}
+	{%- for p in pages -%}
+		{%- if p.slug == slug and p.lang == lang -%}
+			{{- caller(p, "page") -}}
+		{%- endif -%}
+	{%- endfor -%}
+{%- endmacro -%}
+
-- 
GitLab