How to Use a Ready-Made Website in Back-End Framework
Tags: tutorial, beginners, html, design
Published: 2023-12-31 16:28:49

The images below are examples of several ready-made websites that are on the [TOO CSS](https://www.toocss.com) website.

![ready-made website 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c0yq2wq9y0v3qqde3z4n.jpg)

![ready-made website 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7p8y3voxy3d67hc4418.jpg)

![ready-made website 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnd18v6wxy45riz7qnsh.jpg)

There are many such websites on the Internet.

You can find a modern set of ready-made HTML, CSS and JavaScript templates on these websites and get them without registration.

In this article, we want to teach you how to put these static templates into the powerful [CodeBehind framework](https://github.com/elanatframework/Code_behind) and make them dynamic.

Please read the article to the end and tell us and other users how it is to put ready-made templates in the framework you use (Laravel, Django, ASP.NET Core, etc.); then compare it with the CodeBehind framework.

**Step 1:** Choose and download your favorite template.
We selected the Purple Buzz template from the website below.
[https://templatemo.com](https://templatemo.com)

![Purple Buzz template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zptpqlta14suxd263xf2.jpg)

We got the Purple Buzz template zip file and unzipped it. The content of this file is shown in the image below.

![zip file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gw7j1z4ryjtzn8r37iy.png)

The Purple Buzz template contains several html files. The assets directory also contains images, css, javascript and font files.

**Step 2:** In Visual Studio 2022, we create a new empty project under ASP.NET Core version 7.0.

**Step 3:** We install the latest version of CodeBehind framework through NuGet packages.

**Step 4:** Configure the Program.cs class as follows.

```csharp
using CodeBehind;
using SetCodeBehind;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.UseStaticFiles();

CodeBehindCompiler.Initialization();

app.Run(async context =>
{
    CodeBehindExecute execute = new CodeBehindExecute();
    await context.Response.WriteAsync(execute.Run(context));
});

app.Run();
```

**Step 5:** Add the wwwroot directory to the Visual Studio project and then copy the template files into it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqgnr2jjx2wu1hajbqgb.png)

**Step 6:** We rename the index.html file to Default.aspx and change the html extension of other html files to aspx.

**Step 7:** We create the header.aspx file and separate the header and add it to the header.aspx file. We set the attributes of the header.aspx page as follows

```html
@page
@break
    <!-- Start Header -->
    ...
    <!-- End Header -->
```

Note: Adding the @break attribute will prevent the page from being included in the direct call list. For example, the path below will show a blank page.
`https://example.com/header.aspx`

**Step 8:** According to the header, we create the footer.aspx file and separate the footer and add it to the footer.aspx file. We set the attributes of the footer.aspx page as follows

```html
@page
@break
    <!-- Start Footer-->
    ...
    <!-- End Footer -->
```

**Step 9:** In the header and footer files, we replace the path of the link to index.html with the slash (/) character and convert the html extensions to aspx

Example: `href="about.html"` to `href="about.aspx"`

**Step 10:** We create a file named layout.aspx and, apart from the values between header and footer, we add the html tags of one of the aspx files (such as Default.aspx) in it. We also call the header and footer values using the LoadPage method.

The layout.aspx file is as follows

```diff
+@page
+@islayout
<!DOCTYPE html>
<html lang="en">

<head>
+    <title>Purple Buzz - @ViewData.GetValue("title") Page</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="apple-touch-icon" href="assets/img/apple-icon.png">
    <link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.ico">
    <!-- Load Require CSS -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font CSS -->
    <link href="assets/css/boxicon.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600&display=swap" rel="stylesheet">
    <!-- Load Tempalte CSS -->
    <link rel="stylesheet" href="assets/css/templatemo.css">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="assets/css/custom.css">

<!-- TemplateMo 561 Purple Buzz https://templatemo.com/tm-561-purple-buzz -->
</head>

<body>
+    @LoadPage("/header.aspx")

+    @PageReturnValue

+    @LoadPage("/footer.aspx")

    <!-- Bootstrap -->
    <script src="assets/js/bootstrap.bundle.min.js"></script>
    <!-- Templatemo -->
    <script src="assets/js/templatemo.js"></script>
    <!-- Custom -->
    <script src="assets/js/custom.js"></script>

</body>

</html>
```

**Step 11:** In all aspx files (except layout, header and footer), we add the page attribute and set the layout path for them, also we add the title value by calling ViewData.Add.

```html
@page
@layout "/layout.aspx"
@{
    @ViewData.Add("title", "Page Title");
}
<!-- Start Main -->
...
<!-- End Main -->
```

**Step 12:** Run the project and see the result.

![ّFinall result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uc1qi0k10445jknvy4v4.jpg)

### Related links

[CodeBehind on GitHub](https://github.com/elanatframework/Code_behind)

[CodeBehind in NuGet](https://www.nuget.org/packages/CodeBehind/)

[CodeBehind page](https://elanat.net/page_content/code_behind)