question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Templates in folders

See original GitHub issue

I’m just starting to implement RL alpha3 in my 2.0 project. I’ve created a folder in Views/ called Mailers to store all my templates. The plan was to organise these so I have

/Shared <- for _Layout
/Folder1/Template1.cshtml
/Folder2/Template1.cshtml

But I’m not sure how to do this with the engine/key structure. If /Views/Mailers is my root engine, I can’t pass a subfolder in a key to get my core template. If I create the engine in the subfolder, it can’t find the template.

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dombarnescommented, Nov 10, 2017

Sorry for being confusing. Hope this helps.

var webRoot = _env.ContentRootPath;
var engine = new EngineFactory().ForFileSystem(Path.Combine(webRoot, "Views", "Mailers", "Systems" ));
var message = engine.CompileRenderAsync("AdminWelcome", model, viewBag).Result;

So AdminWelcome is my template name, and its in the ContentRoot/Views/Mailers/Systems My Layout is ContentRoot/Views/Mailers/Shared/_Layout.cshtml though, because I use one template for all my emails.
screenshot 2017-11-10 22 49 09

If I’m setting the Systems folder as the engine path, I can’t access the Shared folder (because its a level above the root of the engine). If I set the Mailers folder as the root engine (the contents of which is in the screenshot), I’m not sure how to pass the folder and the template key (cshtml filename) to the engine to render. It doesn’t seem to like taking a path like “Systems/AdminWelcome” as the template key. What I want to be able to do is something like…

var engine = new EngineFactory().ForFileSystem(Path.Combine(webRoot, "Views", "Mailers"));
var message = engine.CompileRenderAsync("Systems/AdminWelcome", model, viewBag).Result;

and in my template be putting

@{ Layout = "/Shared/_Layout.cshtml"}
1reaction
toddamscommented, Nov 9, 2017

Templates are resolved taking as a start point - a root folder that you specify when you create an engine.

So root is your upper folder. Then when you resolve a template you specify the path for it: /Folder/Template1 and in @{ Layout = “/Shared/myLayout” }

Is that what you’ve been asking?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template Folders
Template folders provide a way to organize your Templates list. You create folders from the Templates page. Once you create one or more ......
Read more >
Free Printable PDF Templates for Folders
Download easy-to-use, free folder templates from The Paper Mill Store & order matching paper, cardstock & envelopes for your project.
Read more >
72 Free Presentation Folder Design Templates
Download free, presentation folder design templates for Adobe Illustrator & Photoshop. Browse hundreds of custom business folders created ...
Read more >
How to Customize Your Folder and Library Templates ...
Make file management a breeze with folder and library templates for Windows.
Read more >
Understanding Folder Templates
SmartVault creates a folder structure for your account called Folder Templates as you add clients, create engagements, and add and edit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found