What We’ll Cover
Overview
Razor is a view engine supported in ASP.NET MVC that allows you to mix HTML with server-side code using C#.
DirectScale has integrated this syntax into the Custom Content Editor used to create custom pages and widgets for the Web Office and eCommerce Shop.
Methods
There are three methods that can be used:
User
- Inject user dataGetSsoURL
- Allow for SSO linkingString
- A translatable string can be added
How to Use
In a Custom Content Editor, such as the one for creating custom pages in Web Office, Razor syntax is preceded by an @
sign.
In Web Office Admin, navigate to: Code Customization > Custom Office Pages > Click + ADD PAGE.

Type-Ahead
Once you type your @
sign, the type-ahead feature will display the methods you can select:

If you select the User method, a second menu will display with a full list of data point categories to select.

User Method
Inject user data into the page. With this method, you can access any data you have on a user.
Example:
// Output: Welcome Sam Space from UT!
<p>Welcome @User.AssociateName from @User.AssociateAddressState!</p>
Data Point Categories
See a full list: Data Point Categories
Logic-Determined Markup
All valid Razor markup will compile in an HTML widget. This includes conditionals and loops. To display a line of markup depending on the user’s rank, you might use a line like this:
Example:
@if(User.Rank == "Gold") { <p>You are a distributor. Your next rank isn't far away!</p> }
Example:
//
// Output: IsCurrentUser returns true if the
// logged-in user is viewing their own data.
//
@if (User.IsCurrentUser) { <div>Some Html</div> }
Example:
//
// Output: DownlineLevel(treeName) for the logged-in user’s specified tree
// (Enrollment, Placement, or Matrix) returns the downline level of the
// user whose data is being viewed. If the user is not in the
// logged-in user’s tree then it returns null.
//
@if (User.DownlineLevel("Placement")
GetSsoURL Method
You can use DirectScale’s standard outbound SSO.
To convert a URL so it redirects through DirectScale standard outbound SSO handler use the Razor method’s GetSsoUrl
method. This method accepts the URL to redirect to as an argument.
<a href='@GetSsoUrl("http://mysite.com?token={DirectScale:Token}")'>Click to go to mysite</a>
A URL will generate to DirectScale’s redirect handler, which will replace {DirectScale:Token}
with a temporary SSO token and redirect to the given URL.
Read more: Inbound and Outbound Single Sign On (SSO)
String Method
A translatable string can be added by using the String method. This method accepts the string as an argument.
Example:
<p>@String("Welcome!")</p>
This string will then be available for translation.
-
Click the TRANSLATIONS tab to add translations.
-
Click the
symbol to open the Manage Translations module.
Manage Translations symbol Manage Translations module
Read more: Managing Translations in Web Office Admin
Comments
0 comments
Please sign in to leave a comment.