How to create a plugin for Elanat?
Tags: csharp, dotnet, opensource, tutorial
Published: 2023-08-22 14:23:41

## Introduction

[Elanat](https://elanat.net) is the most powerful .NET CMS. Elanat is a new CMS introduced in 2023. None of the similar .NET systems can be compared to Elanat, neither in terms of unique add-on-oriented structure nor in terms of size. Elanat's architecture is very modern and it is created based on server-side independence. It is interesting to know that the initial implementation of Elanat based on server-side independence caused the transition from .NET Standard version 4.5 to .NET Core version 7.0 to take less than 2 weeks (not counting the preparation of the new version release). Elanat supports eight add-on models, which will even reach 15 including templates, styles, languages, and other items; It is interesting to know that the number of add-ons kind in all systems similar to .net and php will not reach 15.

As promised, we will try to provide the .NET Core version of [Elanat framework](https://github.com/elanatframework/Elanat) in August 2023. Before we try to present the new version, we decided to teach how to make add-ons of the plugin type. So that developers can practice creating plugins before releasing a new version in Elanat dot NET Core version.

This tutorial is for Elanat framework version 2, which is implemented with .NET Core 7.0.
You need to add [CodeBehind](https://github.com/elanatframework/Code_behind) package from nuget in your plugin project.

**tip :**
Remember that after the release of the new version, we will soon add the raw package (hello world!) of the plugin in nuget, so that developers can access the core Elanat dlls to create their plugins very quickly.

Plugins are placed in Elanat in wwwroot/add_on/plugin/yourplugin; your plugin will be automatically added to the directory you specify. This notification was for you to know about the path of your plugin!

## Step 1:
Create empty project
Create an empty ASP.NET Core 7.0 project then add CodeBehind nuget package
[https://www.nuget.org/packages/CodeBehind](https://www.nuget.org/packages/CodeBehind)

## Step 2:
Create Model and View and Controller

**View page file**
```html
<%@ Page Controller="Elanat.YourController" Model="Elanat.YourModel" %><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title><%=model.PageTitle%></title>
</head>
<body>
    <%=model.BodyValue%>
</body>
</html>
```

**Controller class file**
```csharp
using CodeBehind;

namespace Elanat
{
    public partial class YourController: CodeBehindController
    {
        public YourModel model = new YourModel();
        public void PageLoad(HttpContext context)
        {
            model.PageTitle = "Hello World! In Title";
            model.BodyValue = "Hello World! In HTML Body";
            View(model);
        }
    }
}
```

**Model class file**
```csharp
using CodeBehind;

namespace Elanat
{
    public partial class YourModel : CodeBehindModel
    {
        public string PageTitle { get; set; }
        public string BodyValue { get; set; }
    }
}
```

**Program.cs class file**
```csharp
var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.Run();
```

The README.md file in the CodeBehind framework repository provides a complete description of programming with this framework. You can run your project according to the README.md file description. Please note that for the final publication, the Program.cs class must be in accordance with this tutorial(Program.cs class file in step 2).
[https://github.com/elanatframework/Code_behind](https://github.com/elanatframework/Code_behind)

## Step 3:
Download raw add-on file of the plugin
The below link is the raw add-on file of the plugin:
[https://elanat.net/upload/english_presentation_download_center/plugin.zip](https://elanat.net/upload/english_presentation_download_center/plugin.zip)

## Step 4:
Publish your project
First, extract the zip file; after extracting the zip file, you will see two directories; in the directory with the same name as the Add-on type, delete the index.html file and add your executable file in this directory. You can add as many files as you want in the Elanat path in the root directory.
Place the project dll file in the bin directory in the root directory. Note that there is no need to add CodeBehind.dll and you only need to add your project dll file along with the dlls you used in the project.

## Step 5:
Fill catalog.xml file
In the directory with the same name as the add-on type, open the catalog.xml file for editing and change or add the necessary values such as add-on name, add-on path, add-on executable file name, etc. Finally, create a zip file containing the directory with the same name as the add-on type and the root directory.

In the links below, the codes of 3 module-type add-ons and one component-type add-on are available:

[https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/module/elanat_slideshow](https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/module/elanat_slideshow)
[https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/module/elanat_gallery](https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/module/elanat_gallery)
[https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/module/elanat_faq](https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/module/elanat_faq)
[https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/component/sql_command](https://github.com/elanatframework/Elanat_add-ons/tree/elanat_framework/component/sql_command)

## Links:

Website
[https://elanat.net](https://elanat.net)

Elanat framework repository
[https://github.com/elanatframework/Elanat](https://github.com/elanatframework/Elanat)

Elanat external add-on repository
[https://github.com/elanatframework/Elanat_add-ons](https://github.com/elanatframework/Elanat_add-ons)

CodeBehind backend framework repository
[https://github.com/elanatframework/Code_behind](https://github.com/elanatframework/Code_behind)