Any way to specify metadata within a razor page rather than using yaml/json? #132
-
I'd like to specify metadata either through a page model or through attributes on the razor page rather than using a seperate yaml/json frontmatter section or sidecar file, is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Not really. The Razor engine exists at a level "higher" than the Statiq document model. Document metadata can flow up through the document to be exposed in the Razor template via the Part of the reasoning here is that it would be confusing. Razor only executes near the very end of the Statiq process in the post-process phase so even if we did allow metadata to be added to a document from within Razor, it wouldn't really be available to much else after the Razor engine in done processing. On the other hand, there's no reason you can't set common properties or other values like you normally would in Razor. For example, adding this to the top of your layout would work fine:
And What in particular are you trying to accomplish? Maybe that will help me understand what the use case here is. |
Beta Was this translation helpful? Give feedback.
Not really. The Razor engine exists at a level "higher" than the Statiq document model. Document metadata can flow up through the document to be exposed in the Razor template via the
Document
property (and in some casesModel
- thoughDocument
is preferred). But we can't flow metadata back down to the document through the Razor template.Part of the reasoning here is that it would be confusing. Razor only executes near the very end of the Statiq process in the post-process phase so even if we did allow metadata to be added to a document from within Razor, it wouldn't really be available to much else after the Razor engine in done processing.
On the other hand, there's no reason you can't …