Documentation

Best practices and coding conventions

Best practices and coding conventions

Custom portlets are better when written in a clean, concise manner. Adhering to correct coding practices for any language leads to more readable, more maintainable code. This extends to writing ThoughtFarmer custom portlets. When authoring  portlets, always use established .NET naming conventions. This helps other developers understand your code when reading it.

Razor provides a mechanism to define code blocks within your templates that serve specific purposes, such as @function and @helper blocks. As a convention, these blocks should always precede other code used on the page.

Example

@functions {
    string Capitalize(string value)
    {
        return value.Length == 1 ? value.ToUpper() : string.Concat(value.Substring(0, 1).ToUpper(), value.Substring(1));
    }
}

<div> @Capitalize(Model.CurrentUser.DisplayName) </div>

 

Deferred loading of JavaScript

To improve client side performance all scripts should use the deferred pattern of loading JavaScript. Please see deferred loading of JavaScript for more information. If you are not able to utilize this pattern then you should disable the configuration setting javascript.deferredLoading.