hishamco / MarkdownViewEngine

Markdown View Engine for ASP.NET Core
http://hishambinateya.com/introducing-a-new-markdown-view-engine-for-asp.net-core
MIT License
43 stars 3 forks source link

Support layout and page title in same page? #5

Closed jskeet closed 7 years ago

jskeet commented 7 years ago

I have two different layouts I need to support: one for the user guide, and one for a developer guide.

Ideally, I could default to the user guide but have a file in the developer directory that changes the layout. However, failing that, it wouldn't be awful to have:

@layout DeveloperLayout.md
@page title="Foo"

in each developer guide page. But at the moment, I think only a single directive is supported per file. Perhaps it should read a line at a time until it finds something which isn't a directive (and processing the directives as it goes), and then concatenate the rest of the file with that...

jskeet commented 7 years ago

Ooh, it looks like I can put a _ViewStart.md in each view directory, and that will be picked up. That will be a fine solution for me...

jskeet commented 7 years ago

Nope, that doesn't work - I've tried a few things, and although a single _ViewStart.md with @layout _Layout looks like it might work, I don't see any way of specifying a layout relative to the page itself. I think I can make do with two controllers, although it's a bit ugly...

hishamco commented 7 years ago

@jskeet I change the directives little bit last week but I didn't push the updates yet, hope I will do it soon. Regarding _ViewStart it is limited now so the engine only able to pick it from the shared folder

hishamco commented 7 years ago

Uploading the latest change will fix the issue. Also I will look to support multiple _ViewStart so you will be able to add one in each folder

jskeet commented 7 years ago

RIghto - will use different controllers just for now, but fix it later - thanks :)

jskeet commented 7 years ago

No need for multiple _ViewStart in this particular case, so long as there's a way of making a single @layout directive work relative to the rendered Markdown page - I can just call the layout _Layout.md in every directory.

hishamco commented 7 years ago

Yes you can, but it's tedious 😄, we can support _ViewStart per folder such as Razor Engine

hishamco commented 7 years ago

After looking to the latest code the @page directive introduces a property called Layout instead of the @Layout directive, so this absolutely will solve your issue

hishamco commented 7 years ago

@jskeet after this commit https://github.com/hishamco/MarkdownViewEngine/commit/ac6800b4b1df8d6a9d0ed30efb6efc03193c5bb2 this should be fixed. You can have a look to this https://github.com/hishamco/MarkdownViewEngine/blob/master/samples/MarkdownViewEngineSample/Views/Home/Index.md and https://github.com/hishamco/MarkdownViewEngine/blob/master/samples/MarkdownViewEngineSample/Views/Home/About.md which there are using different layouts