Page Title Format #72
-
Hello, I have a few pages where the formatting of the name is important (stylized product names). I am building a navigational sidebar which needs to use these stylized names. The sidebar is held in a partial which is rendered next to the main content as so: <div class="is-container">
<div class="main-sidebar">
<partial name="_projectsSidebar" />
</div>
<div class="main-content">
<div class="box">
@RenderBody()
</div>
</div>
</div> Here is the code for the sidebar. Following is how the entry for the currently selected page renders: <div class="box is-hidden-mobile">
<h3>Forms</h3>
<nav>
<ul>
<li>
<a href="@indexLink">Projects</a>
</li>
@foreach (IDocument document in OutputPages.GetChildrenOf(contactRoot).OrderBy(x => x.GetTitle()))
{
// var title = document.GetString(Constants.Title) ?? document.GetTitle();
var title = @ViewData[Constants.Title];
<li>@Html.DocumentLink(document)</li>
<ul>
<li>ViewData[Title]: @title</li>
<li>document.GetString(Keys.Title): @document.GetString(Keys.Title)</li>
<li>document.Source.GetTitle(): @document.Source.GetTitle()</li>
</ul>
}
</ul>
</nav>
</div> Collecting the title from Am I able to store this stylized title information in an alternate location, such as in front matter or in a sidecar? The pages in question are all razor pages, so I'm not sure if I'm able to manipulate front matter directly in the initialization block for the page. Here's what my current setup for the RavenRock RP page looks like, in case it helps: @{
ViewData[Constants.Title] = "RavenRock RP";
ViewData[Constants.OpenGraphTitle] = ViewData[Constants.Title];
ViewData[Constants.OpenGraphDescription] = "Free community roleplay project based in Minecraft.";
Layout = "_ProjectsLayout";
}
<h1>RavenRock RP</h1> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The short answer is "yes" :) I know you've been using Wyam/Statiq for a while, so you probably already know some/most of this, but I'll start from the basics for completion and in case anyone else stumbles here...
In Statiq the document itself is essentially the same thing. Statiq continues to provide the So now the question is: what's the equivalent of:
but that gets evaluated for every view (I.e. every .cshtml file) and will be available when generating the navigation. Frontmatter to the rescue:
Notice that I'm still using a code block to specify the layout (though that could also be moved out to a common Statiq will parse everything above the Then when you're iterating over documents, you can access those values like this: |
Beta Was this translation helpful? Give feedback.
The short answer is "yes" :)
I know you've been using Wyam/Statiq for a while, so you probably already know some/most of this, but I'll start from the basics for completion and in case anyone else stumbles here...
ViewData
is essentially a per-page dictionary that ASP.NET and Razor maintain for you. In a standard ASP.NET server-style application, you can set stuff inViewData
through a controller or action, middleware, etc. and it's available to the view. But as you noted, theViewData
is specific to a particular "rendering" of a view and not actually tied to the more general concept of that Razor file or page. In a server environment this makes sense given that a request is only ever goi…