func (btr *BeuboTemplateRenderer) RenderHTMLPage(w http.ResponseWriter, r *http.Request, pageData structs.PageData) {
	if os.Getenv("ASSETS_DIR") != "" {
		rootDir = os.Getenv("ASSETS_DIR")
	}
	errorMessage, err := utility.GetFlash(w, r, "error")
	utility.ErrorHandler(err, false)
	warningMessage, err := utility.GetFlash(w, r, "warning")
	utility.ErrorHandler(err, false)
	stringMessage, err := utility.GetFlash(w, r, "message")
	utility.ErrorHandler(err, false)
	siteName := "Beubo"
	site := r.Context().Value(middleware.SiteContextKey)
	user := r.Context().Value(middleware.UserContextKey)
	if site != nil {
		btr.CurrentTheme = site.(structs.Site).Theme.Slug
		siteName = site.(structs.Site).Title
	} else if os.Getenv("THEME") != "" {
		btr.CurrentTheme = os.Getenv("THEME")
	} else {
		if btr.CurrentTheme == "" {
			btr.CurrentTheme = "default"
		}
	}
	scripts := []string{
		"/default/js/main.js",
	}
	stylesheets := []string{
		"/default/css/main.css",
	}
	if strings.HasPrefix(r.URL.Path, "/admin") {
		scripts = append(scripts, "/default/js/admin.js")
		stylesheets = append(stylesheets, "/default/css/admin.css")
	}
	var userFromContext structs.User
	if user != nil && user.(structs.User).ID > 0 {
		userFromContext = user.(structs.User)
	}
	data := structs.PageData{
		Stylesheets: stylesheets,
		Favicon:     "/default/images/favicon.ico",
		Scripts:     scripts,
		WebsiteName: siteName,
		URL:         "http://localhost:3000",
		Error:       string(errorMessage),
		Warning:     string(warningMessage),
		Message:     string(stringMessage),
		Year:        strconv.Itoa(time.Now().Year()),
		Menus:       btr.buildMenus(userFromContext),
	}
	data = mergePageData(data, pageData)
	if btr.PluginHandler != nil {
		data = btr.PluginHandler.PageData(r, data)
	}
	if btr.ReloadTemplates {
		log.Println("Parsing and loading templates...")
		var err error
		btr.T, err = findAndParseTemplates(rootDir)
		utility.ErrorHandler(err, false)
	}
	var foundTemplate *template.Template
	path := fmt.Sprintf("%s.%s", btr.CurrentTheme, pageData.Template)
	if foundTemplate = btr.T.Lookup(path); foundTemplate == nil {
		path := fmt.Sprintf("%s.%s", "default", pageData.Template)
		if foundTemplate = btr.T.Lookup(path); foundTemplate == nil {
			log.Printf("Theme file not found %s\n", path)
			return
		}
	}
	err = foundTemplate.Execute(w, data)
	utility.ErrorHandler(err, false)
}
RenderHTMLPage handles rendering of the html template and should be the last function called before returning the response
package template
import (
	"fmt"
	"github.com/uberswe/beubo/pkg/middleware"
	"github.com/uberswe/beubo/pkg/plugin"
	"github.com/uberswe/beubo/pkg/structs"
	"github.com/uberswe/beubo/pkg/structs/page"
	"github.com/uberswe/beubo/pkg/structs/page/menu"
	"github.com/uberswe/beubo/pkg/utility"
	"gorm.io/gorm"
	"html/template"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
)
var (
	currentTheme = "default"
	rootDir      = "./"
)
type BeuboTemplateRenderer struct {
	T               *template.Template
	PluginHandler   *plugin.Handler
	ReloadTemplates bool
	CurrentTheme    string
	ThemeDir        string
	DB              *gorm.DB
}
func (btr *BeuboTemplateRenderer) Init() {
	log.Println("Parsing and loading templates...")
	var err error
	btr.T, err = findAndParseTemplates(rootDir)
	utility.ErrorHandler(err, false)
}