Computer Magic Logo
Comments

Saturday, August 8, 2015

Published by Aristotelis Pitaridis

There are two ways of adding comments on a Template using the Razor syntax. The first way used inside a code block where we can add comments as we do in a C# class. Below we can see an example of such a case.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = null;

    // One line comment
    
    /* Multiline
       Comment */
}

The first commend is a one line comment the way we use it in C#. In order to do it we type two times the slash character and after that we type the comment.

The second comment can be used when we want to comment multiple lines inside a code block. In order to start the comment we type the slash character followed by an asterisk character. When we finish typing the comments we type an asterisk followed by the slash character in order to define the end of our comment.

The second way of adding a comment on a Template is when we want to comment parts of the html which is located out of a code block. Below we can see how to comment a paragraph tag on a template.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = null;

    // One line comment
    
    /* Multiline
       Comment   */
}

@*<p>Hello world!</p>*@

As we can see in order to define a Razor comment for our HTML we can define the beginning of the comment block by typing the @ character followed by the asterisk character. In order to define the end of the commend we type the asterisk character followed by the @ character. With this comment syntax we can comment multiple lines of HTML.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = null;

    // One line comment
    
    /* Multiline
       Comment   */
}

@*<p>Hello world!</p>*@
	
@*
    <p>First line</p>
    <p>Second line</p>
    <p>Third line</p>
    <p>Fourth line</p>
*@