Template Store Service
The Problem
After adding the templating solution to our project, we needed a way to organize the code and store the templates script tags in separate files and call them in the CSHTML so the code would be more organized and cleaner.
Folders Structure
There is a file in the solution inside Pages Folder under the Shared Folder called Templates, all the templates will be store there.
Under the Templates Folder there’re the Themes Folders, In each theme folder there are the folders of the parent of the template (for example inside Courses will be stored every template related to Courses Page) and in every parent there is a folder called UniqueTemplates , this folder will stored the unique templates if the platform require unique templates for the parent.
How To Use it
- Create your template inside it correct location (the extension of the file is .handlebars for organization matter).
- Inject The Service inside your CSHTML File.
- Call The LoadTemplate Method from the Service and give it the Parent Name and the Template Name and if the file is unique or not .
- Add your script tag of type text/x-handlebars-template and add the result of the service inside it.