adding partials for <include>
This commit is contained in:
17
layouts/partials/include.html
Normal file
17
layouts/partials/include.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{{/*
|
||||||
|
Partial: include.html
|
||||||
|
Handles including external Markdown files and rendering them.
|
||||||
|
Parameters:
|
||||||
|
- context: The Page context (required for RenderString)
|
||||||
|
- path: Path to the file, relative to the project root
|
||||||
|
*/}}
|
||||||
|
{{- $path := .path -}}
|
||||||
|
{{- $context := .context -}}
|
||||||
|
|
||||||
|
{{- if fileExists $path -}}
|
||||||
|
{{- $content := readFile $path -}}
|
||||||
|
{{- $context.RenderString $content -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Include file not found: %s" $path -}}
|
||||||
|
<p class="text-red-500 font-bold">[Include Error: File "{{ $path }}" not found]</p>
|
||||||
|
{{- end -}}
|
||||||
10
layouts/shortcodes/include.html
Normal file
10
layouts/shortcodes/include.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{{- $path := .Get 0 -}}
|
||||||
|
{{- if not $path -}}
|
||||||
|
{{- $path = .Get "src" -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $path -}}
|
||||||
|
{{- partial "include.html" (dict "context" .Page "path" $path) -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Shortcode 'include' called without path or src attribute." -}}
|
||||||
|
<p class="text-red-500 font-bold">[Include Error: No path provided]</p>
|
||||||
|
{{- end -}}
|
||||||
Reference in New Issue
Block a user