Default Razor Function
Take a closer look at a Razor function created by default.
When you create a Razor function in the CMS Console, it will already have some sample code that you can reuse or replace with your own code.
@inherits directive
All Razor functions in C1 CMS must inherit from RazorFunction
.
@inherits RazorFunction
Description
Within the @function {...}
directive, you can specify the function's description with the FunctionDescription
function.
@functions { public override string FunctionDescription { get { return "A demo function that outputs a hello message."; } } }
The description is visible in the CMS Console GUI when you edit the function properties in the Advanced view.
The description is optional but is a good practice to have one in your Razor function.
The new function comes with a sample description which you can change to your own.
Parameters
The new function also comes with a few sample parameters used in the markup below.
@functions { [FunctionParameter(Label = "Heading label here...", Help = "Help text here...", DefaultValue = "Default value here...")] public string Heading { get; set; } [FunctionParameter(Label = "Article label here...", Help = "Help text here...")] public XhtmlDocument Article { get; set; } [FunctionParameter(Label = "Image label here...", Help = "Help text here...")] public DataReference<IImageFile> Image { get; set; } }
You can remove the parameters altogether (and remember to remove them in the markup).
You can add your own parameters or add none. Read more on defining parameters in Razor Functions.
Markup
The new function also includes some sample XHTML.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0"> <head> </head> <body> <h1>@Heading</h1> <div> <img src="/media(@Image)" style="float:right" /> @Html.Raw(@Article) </div> </body> </html>
You are free to change it the way you need or totally remove it from your function.