statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.
https://statiq.dev/web
Other
1.64k stars 234 forks source link

Question: Include example #1013

Open AlexHedley opened 1 year ago

AlexHedley commented 1 year ago

Do you have examples of the different shortcodes?

I'll like to use the include to create a Table of Contents, once, and use it in other posts.

I created another markdown file toc.md and put it in another directory inputs/includes.

Added the following to my post:

<?# Include "./../includes/posts/toc.md" /?>

But when built the site it added it as raw text not markdown.

Is there another attribute I need to set?

AlexHedley commented 1 year ago

Should it be

<?! Include "./../includes/posts/toc.md" /?>

https://www.statiq.dev/guide/content-and-data/shortcodes#processing-phases

Performed before any other templating engines like Markdown or Razor. That means any output from a shortcode in this phase will be processed by those engines. For example, if you want to include a Markdown document in another Markdown document, you'll need to evaluate the Include shortcode during the pre-rendering phase (otherwise the Markdown processor would have already been run and your included Markdown document would never get processed).

AlexHedley commented 1 year ago

Alternative

Relative

<?# Markdown ?>
<?!^ "./../includes/posts/toc.md" /?>
<?#/ Markdown ?>

Absolute

<?# Markdown ?>
<?!^ "https://raw.githubusercontent.com/alex-hedley/statiqweb-example/main/src/includes/posts/toc.md" /?>
<?#/ Markdown ?>