cre8magic β How It Works
Below weβll give you an example of what you would normally have, and how it would be done with cre8magic.
Example Problem: Smart Module Containers
Letβs assume you have a container which is a bunch of div
tags and a bit of CSS.
In this example we have two features we are using
- a special ID for CSS targeting (for special cases where we wish to have CSS for a very specific module)
- some CSS classes which could vary depending on certain factors - such as if itβs unpublished to show something is wrong
Classic Solution
@inherits Oqtane.Themes.ContainerBase
<div id='module-@ModuleState.ModuleId' class='to-shine-background-container py-4 @(CheckIfModulePublished() ? "" : "module-unpublished") @(ModuleState.UseAdminContainer ? "to-shine-admin-container" : "...")'>
<div class="container">
<Oqtane.Themes.Controls.ModuleActions/>
<ModuleInstance/>
</div>
</div>
@code
{
public bool CheckIfModulePublished()
{
return UserSecurity.ContainsRole(ModuleState.Permissions, PermissionNames.View, RoleNames.Everyone);
}
}
Based on this example you can see, that there is a mix of logic and design which is
- hard to read
- hard for a designer to develop
- error prone
- hard to maintain
Simple with cre8magic
Hereβs how it works with cre8magic:
@inherits MagicContainer
<div id='@Value("Id")' class='@Classes("div")'>
<div class="container">
<Oqtane.Themes.Controls.ModuleActions/>
<ModuleInstance/>
</div>
</div>
For the system to know what it should do, there are Magic Settings which are easy to manage. Below weβre only showing the settings relevant to this example, there are of course more:
{
"themeDesigns": {
"Default": {
// ...a lot of settings not relevant for this example...
// Container Designs determine CSS classes on containers
// The default/normal container
"container": {
"classes": "theme-container py-4 demo-module-[Module.Id] demo-page-[Page.Id]",
"isPublished": [null, "module-unpublished"],
"isAdmin": "theme-container-admin app-admin-modal",
"id": "module-[Module.Id]"
},
}
}
}
The Magic in the Background
cre8magic will do a bunch of things in the background, such as:
- Load configuration from
- the DB targeting the page (WIP)
- the DB targeting a branch in the menu (WIP)
- the DB targeting the site (WIP)
- JSON targeting all kinds of scenarios
defaults in your code(not recommended)- final defaults in cre8magic
- Flatten configurations to match the current theme
- Use names to find the configuration for the theme
- Use further names to find the configuration for each part, such as Menus, Breadcrumbs etc.
- Flatten all to the current scenario
- Broadcast these flattened Magic Settings from the Theme to all Controls
- Initialize the proper settings
- Broadcast these settings to all controls that are somewhere within the theme object tree
- Provide simple accessors
- The
MagicTheme
,MagicContainer
,MagicControl
etc. all pick up the settings automatically - β¦and have special APIs such as
@Classes(...)
helpers to retrieve the values
- The
- Process Tokens
- Settings can contain tokens such as
[Module.Id]
which will be rendered into the final result
- Settings can contain tokens such as
TL;DR
You got this far? Letβs go back to home and start designing!
ππΎ Home