Skip to content

How to pass some "active content" (or callback function) to partials? #504

Answered by McShelby
cagix asked this question in Q&A
Discussion options

You must be logged in to vote

Sure. Basically:

{{ $c := "<strong>blub <span style='color:red;'>red</span></strong>"}}
{{ partial "shortcodes/notice.html" (dict
"context" .
"style" "primary"
"title" "Hot shit"
"icon" "skull-crossbones"
"content" $c
)}}

Replace the $c := ... part with

{{ $quizzes := .Params.quizzes }}
$c := "<ul>"
{{ range $quizzes }}
    {{ $name := index . "name" }}
    {{ $link := index . "link" }}
    $c = printf "%s%s" $c "<li><a href=\"" + $link "\">" + (default $link $name) + "</a></li>"
{{ end }}
$c = printf "%s%s" $c "</ul>"

I haven't tested the code and hope there are no typos.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@cagix
Comment options

@McShelby
Comment options

@cagix
Comment options

Answer selected by cagix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants