Render/display view in layout.cshtml

Topics: Core, General
Nov 5, 2015 at 9:08 PM
Edited Nov 5, 2015 at 9:08 PM
Hello all,

What is the correct Razor syntax for rendering a view in my layout.cshtml ?

I have a file called FacebookIcon.cshtml, which consists of SVG code for a Facebook icon, currently inside my theme's /views folder.

Also, is it possible to put this file inside an /svg directory, which would be inside my theme's /views directory, and render it from there?

I'm trying:
and even though it's not erroring, it's not printing anything.

Thank you!
Nov 5, 2015 at 11:06 PM
Edited Nov 5, 2015 at 11:07 PM
You can either render it using Html.RenderPartial (which is the MVC way), or using Display (which is the Orchard and the cool-kids way). To do the latter, you need to first instantiate a shape with the name of your Razor view and then render it. For example, the following code will instantiate a new shape called FacebookIcon and render that using the Display method:
The New property is an instance of IShapeFactory which, when invoke as a dynamic instance, creates a shape instance of the method name you used (FacebookIcon).

Or, as a shortcut, the Display object can create the shape for you and render it using a single call, like this:
That is the ultra-cool way of doing it.
Nov 6, 2015 at 2:23 PM
Thanks sfmskywalker - I'm one of the cool kids, I swear!

Seriously, the shorthand is great. Now, if I wanted to plop some files inside different directories inside the /views folder for better organization, how would I access those when rendering the shape?
Nov 8, 2015 at 4:19 PM
I'm afraid you can't do that without modifying code in some view engine class and configure the folder names to search. Although Html.Partial supports explicitly specifying a view path, shapes don't support that as far as I know (would be a cool-kids feature though).
Nov 9, 2015 at 3:29 PM
Thanks sfmskywalker - I might have to go with Html.Partial in that case, as the benefits of keeping those svgs in their own directory are considerable. Would the performance difference be negligible between that and the Orchard Display() method ?
Nov 10, 2015 at 12:47 PM
I have no idea which one would be faster, but I would not be surprised if Html.Partial would win.