1 ModFrame Basics - lilpug/ModFrame GitHub Wiki

Structure

The ModFrame environment is split into the following folders:

  • layouts
  • modules
  • ModFrame\config
  • ModFrame\global
  • plugins

The following is a brief summary of what each of these folders achieves in ModFrame:-


Layouts: This holds the different layout modules for the MVC project

Modules: This holds groups of modules that our MVC project is created from

Config: This holds our JSON configuration and C# representations that pull the data out of the JSON configuration file.

Global: This is a single module but everything in it is applied globally to all modules and layouts.

Plugins: This stores additional external and internal JS and CSS files for the project.


The Includes Folder

The layouts, modules and the global folder all have the "includes" folder structure in ModFrame.

This folder consists of the following structure:-

includes\
         header\*.cshtml
         footer\*.cshtml

All “*.cshtml” files are automatically pulled in by ModFrame at runtime to every page which renders views.

ModFrame uses the ViewData object to store flags that allow us to determine what page or layout is being used at runtime. By doing this we can then wrap our CSS and JS links to only specific pages or layouts.

In short within these “.cshtml” files and within either your layout action filter or module controller action a flag is set in the ViewData object to allow ModFrame to determine what links should be included in the current page load.


Example

File: Controllers\home.cs

public partial class HomeController : MyController
{   
    [Route("")]   
    public IActionResult Index()
    {
        //Sets the variable so the includes of css and js will pull through
        ViewData["homePage"] = true;
        
        return this.ModuleView("Examples", "MVC", "index.cshtml");        
    }    
}

File: Includes\header\default.cshtml

@if (ViewData["homePage"] != null)
{
    <link …… />
}

File: Includes\footer\default.cshtml

@if (ViewData["homePage"] != null)
{
    <script …… ></script>
}

The ModFrame Loader (optional)

ModFrame comes with a built-in loader process to execute all functions within the "ModFrameLoader" class that have the "LoaderParameter" parameter. This is achieved with the help of using partial classes, by doing this it means you could have a loader file for each module and it will still get executed at the start of the application. The idea of this process is to typically help with loading caches and static variables into memory when the application is booting up for the first time.


The following code can be placed multiple times in any ".cs" files at any location within the project.

Note: Please ensure you give the function a unique name for each entry.

public partial class ModFrameLoader
{
    public void AUniqueFunctionName(LoaderParameter temp)
    {
        //This code will be loaded when booting up for the first time.
    }
}

Extra ModFrame Routing (optional)

By default ModFrame uses the generic MVC routing but ModFrame does comes with a built-in route loader process which loads all the route functions within the "ModFrameRouting" class that have the "IRouteBuilder" parameter. This is achieved with the help of using partial classes, by doing this it means you could have multiple routing files throughout your project and they would still all get loaded at runtime. The idea of this process is to allow custom routing maps to be added into ModFrame if they are required.


The following code can be placed multiple times in any ".cs" files at any location within the project.

Note: Please ensure you give the function a unique name for each entry.

public partial class ModFrameRouting
{
    public void AUniqueFunctionName(IRouteBuilder routes)
    {
        //Adds the generic mvc routing
        routes.MapRoute
            (
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}"
            );
    }
}
⚠️ **GitHub.com Fallback** ⚠️