The introduction of the .NET Core Renderer was the first step in a long-term project of migrating Sitefinity to the .NET Core framework.
This self-contained presentation layer, which can be hosted, developed and deployed independently from the content management UI and operational backend, ushers in a whole new set of page editing concepts and capabilities.
In this blog post, we’ll follow the steps it took to create a sample .NET Core page. The page was built using the new editor and one of the best things about it is the excellent WYSIWYG experience. Just see for yourself.
Interested? Let's dig right in...
First, we need to set up the Sitefinity instance, to which we are going to connect our .NET Core renderer. Download the solution and follow the steps outlined in this repository of Sitefinity samples. Once you have set up the project, you should have a page—Quantum Sample Page—marked with a “new editor” label, a Testimonial content type and a Register Form (make sure you precisely follow all the steps in the readme files).
Next up, follow the instructions of connecting Sitefinity to a standalone ASP.NET Core application to configure your instance to work with the .NET Core renderer.
Let’s begin setting up our .NET Core renderer project. You can opt for the starter template provided by the Sitefinity team or you can follow the instructions in this documentation article to create a blank .NET Core application. In this demo, I’ll be using the starter template.
This is where you can find the complete starter template. All you need to do is change the URL in the appsettings.json to match that of the Quantum sample project, which we set up early on.
Once the template is downloaded, open it with the IDE of choice and change the URL of the Sitefinity instance under appsetings.json “Sitefinity” -> “URL”.
"Sitefinity": {
"Url": "http://nstefano.com:8080",
"WebServicePath": "api/default"
}
In case the out-of-the-box widgets just don’t suit your design needs, you can go ahead and create custom ones inside the .NET Core project. For the sake of the demo, the widgets we need would be:
Note that the Layout widget is used as a placeholder for other widgets. The Content widget is used to present content, static or dynamic.
Let’s start with the Static section widget. It’s there for you to insert a section widget with specific markup. You can get this widget straight from the sample page repository. Just copy the following files to their corresponding directories:
All *.cshtml files to [Views/Shared/Components/StaticSection]
Now, we can focus on creating the Testimonial widget. Following the steps in the create a custom .NET Core widget article, we need to create the following files into the relevant directories, as follows:
After all the files have been created, we need to add the following line `services.AddScoped<ITestimonialModel, TestimonialModel>();` to the method `ConfigureServices()` in `Startup.cs`. The AddScoped method registers the service with a scoped lifetime—that of a single request.
public void ConfigureServices(IServiceCollection services)
{
// add sitefinity related services
services.AddScoped<ITestimonialModel, TestimonialModel>();
services.AddSitefinity();
services.AddViewComponentModels();
}
Lastly, we need the “Demo request form” widget.
Once we are done with the development of widgets, we can start preparing to style the page. First off, we need to tell the .NET Core project to use static files. We can do that by adding `app.UseStaticFiles();` to `ConfigureServices()` method in `Startup.cs.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseSitefinity();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapSitefinityEndpoints();
});
}
Now we need some styles, scripts and fonts. All of the source files used for the styling of the page will be placed in “client-src” directory. Just get all the files from the sample client-src folder and place them into your project. In order to “play” with them you need to install NodeJS (version 14.15.1) and run “npm i" and “npm start”.
This will precompile all the SCSS file to CSS, copy all the needed assets (fonts) and minify the sample's JavaScript file, placing them all into the “wwwroot” directory. We then link the files in Layout.cshtml which is located in Views/Shared.
Build and start the .NET Core project and navigate to Sitefinity through localhost:5000/sitefinity (5000 is the default .NET Core project port). Open Pages and select “View” for Quantum sample page or navigate directly to localhost:5000/netcore-renderer/quantum-sample-page. Looks good, doesn’t it?
Now let me go over the steps we need to take implementing the design of the page. For the purpose of the demo, we are going to create another .NET Core page and call it “Quantum sample page 2”. Next up, we select “_Layout.cshtml” (.NET Core templates) for the page template.
I will break down the styling into the three major components: Layout, Main and Footer.
For the Layout section, we’ll create the foundation of the page. Starting with an empty page, we need to add two section widgets one after another.
The display settings for Padding and Margins represent CSS classes. These classes can be changed by modifying the corresponding properties in “OffsetClassess” in “appsettings.json”. By default, they represent Bootstrap 4 spacing utilities classes.
There you go, we are done with the Layout of the page and it should look like this.
Let’s continue with the Main section. This one will need a bit of extra work:
<h4 class="qu-txt-white mb-2">QUANTUM WEB DESIGN WIZARD</h4>
<h1 class="qu-txt-white">Complete redesign for less than a week? We do this.</h1>
In order to switch to View HTML simply select the markup button shown below.
Edit the CTA widget and type “Get a free demo” in the Primary action field under Action label. In Display settings, change the value from Primary action to Secondary action. Set Margin top to M.
Edit the second Content block, switch to View Html and insert the following:
<h2>Improve the Customer Experience on Your Website</h2>
Column 1 = “col-lg-5 col-md-12"
Column 2 = “col-lg-1 col-md-12"
Column 3 = “col-lg-6 col-md-12 mt-lg-0 mt-5 pl-xl-5"
<p class="qu-txt-gray qu-txt-medium">We design beautiful websites for any business, portfolio, organization and more with the help our wizard designers and front-end gurus.</p>
Switch to HTML view and paste the following:
<div class="media">
{{image markup}}
<div class="media-body">
<h4>EASY TO CHANGE</h4>
<p class="qu-txt-gray">Enable marketers to manage the look and feel of your website
by applying the color scheme of their campaign.</p>
</div>
</div>
Now replace {{image markup}} with the actual markup from the previously inserted image. At the end all should like something like this:
<div class="media">
<img sf-custom-thumbnail="true" src="http://localhost:5000/images/default-source/quantum-sample-page/a1.png?Status=Master&sfvrsn=43fbcc09_0" style="margin-right:10px;" sf-size="8218" width="80" alt="..." sf-constrain-proportions="true" sfref="[images%7COpenAccessDataProvider]b9038a2f-59f8-46a8-b9c5-a310aa9c758e"
/ data-sf-ec-immutable="">
<div class="media-body">
<h4>EASY TO CHANGE</h4>
<p class="qu-txt-gray">Enable marketers to manage the look and feel of your website by applying the color scheme of their campaign.</p>
</div>
</div>
Edit the second Content block, switch to View Html and insert the following:
<h2>Mobile-Ready Solution Out of the Box</h2>
Column 1 = “col-lg-5 col-md-12"
Column 2 = “col-lg-1 col-md-12"
Column 3 = “col-lg-6 col-md-12 mt-lg-0 mt-5 pl-xl-5"
<p class="qu-txt-gray qu-txt-medium">Quickly create a mobile site optimized for any device. All our designs are touch-friendly, easy to customize and offer accelerated mobile pages.</p>
And that’s that, we are ready with the Main section. Just make sure you check out the Page structure as well, as we changed section labels in order to be more visible in the structure.
One more section left, and here is how we are going to go about it:
<h2 id="get-free-demo" class="qu-txt-white">Get a Free Demo</h2>
Column 1 = “col-lg-5 col-md-12"
Column 2 = “col-lg-1 col-md-12"
Column 3 = “col-lg-6 col-md-12 mt-lg-0 mt-5 pl-xl-5"
<hr class="-white" />
<p class="qu-txt-white qu-txt-small">Copyright © 2020 Quantum. All rights reserved.</p>
And, we are done with the last section of our page. Doesn’t look bad, does it?
Feel free to give it a try and follow the conversation in our dedicated community thread. There, you can mix with like-minded people and keep up with the latest on Sitefinity and .NET Core. You’re most welcome to join our dedicated .NET Core webinar and discover how the new 3-tier architecture helps you future-proof your projects. Hit the link below to reserve your seat.
Register For a Live .NET Core Webinar
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites