Skip to content

Shortcodes using cshtml #129

Answered by daveaglick
ror3d asked this question in Q&A
Feb 2, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

I think the closest you're going to get to HTML-based components right now is Razor partials. Because Markdown accepts arbitrary HTML elements, and Statiq passes rendered Markdown on to a Razor processor, you should be able to call a partial by wrapping it in an HTML element. Something like:

# My Markdown File

Hello.

<div>@await Html.PartialAsync("_EditLink", new Dictionary<string, string> { { "EditLink", "Value1" } })</div>

And then in _EditLink.cshtml you could have something like:

@inherits StatiqRazorPage<Dictionary<string, string>>
<a
    class="is-push-right"
    href="@(Model["EditLink"])"
    target="_blank"
    rel="noreferer noopener"
    style="text-decoration: none">
      …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@ror3d
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ror3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants