Files
Ocam pages may be written in several formats. In addition to vanilla HTML,
files may be written in C# Razor and Markdown. Any files that are not in
one of these formats are copied to the Html
output directory verbatim.
This behavior makes it easy to structure your site any way you like, including
having separate image, script, and style directories.
Content
Any content that is not a Razor or Markdown file is copied verbatim to the
output Html
directory.
Razor
Any .cshtml
files under the Site
directory will be loaded and
executed during the build process. Their contents will be rendered to the
Html
directory.
The backing class for these pages is the PageTemplate<>
class and the
model is PageModel
.
@{
Layout = "Main";
ViewBag.Title = "Home";
}
<h2>@ViewBag.Title</h2>
<p>Welcome!</p>
Markdown
Any files with the extension .markdown
or .md
will be processed
as Markdown and the result will be stored under the Html
directory.
Ocam processes the result of the Markdown transformation as Razor. This only works to a limited degree due to differences in syntax. In particular, variables and model properties work, while block-level constructs generally don't.
Ocam Markdown files support a front matter section in the style of Jekyll,
which is delimted by ---
markers. This section is parsed as C# as if
it were in a @{ ... }
code block at the head of a Razor file.
Here is the equivalent of the above page in Ocam flavored Markdown.
---
Layout = "Main";
ViewBag.Title = "Home";
---
@ViewBag.Title
===
Welcome!
Note that you must excape the @ symbol with a double @@ symbol if you want it to appear in the rendered output.
This is required because Markdown files are postprocessed as Razor files.
The @ symbol is interpreted as the begining of a Razor expression,
which allows you to to reference Model properties or invoke helpers, such
as @Link()
.
This requirement does not exist for code blocks. The @ symbol in a code block is automatically escaped, making it easier to paste C# code into a Markdown file.
Templates
There are several template flavors: layouts, includes, and templates. Generic templates are experimental and won't be covered here.
Layouts
A layout file is much like it's cousin in ASP.NET MVC.
It is used to define the structure of an HTML file that can be shared between pages.
The only requirement is that @RenderBody()
be called somewhere in the file.
<html>
<head>
<title>@ViewBag.Title</title>
<link rel="stylesheet" href="@Href("~/styles/main.css")" />
</head>
<body>
@RenderBody()
</body>
</html>
Includes
Includes are pieces of code or markup that can be reused from other content or layout files.
<nav>
<ul>
<li><a href="@Link("index.md")">Home</a></li>
<li><a href="@Link("about.md")">About</a></li>
</ul>
</nav>
To reference an include, use the Include
method:
@Include("NavMenu")
Includes are similar to MVC partials.