This project is read-only.

Tip: Orchard.Layouts

Topics: General
Mar 11, 2015 at 11:08 PM
Edited Mar 11, 2015 at 11:14 PM
Sorry for being long-winded, here is a tip on using Orchard.Templates to create a template in the AdminUI and then use that Template in Orchard.Layouts. While this, in and of itself, is not too fabulous, what is fabulous is the ability to pass current data (namely, the logged in user).

Yes, you can create a .cshtml file that contains the shape. Yes, you can pass current data doing that. But in this case, thanks to @Sipke and the Orchard team, you can do this in the AdminUI.

1) Create a Layout

  • Go to Admin > Layouts.
  • Call it Test Layout.
  • Don't forget to click "Publish Now" after you add everything (and each time you add new elements after saving).

2) Drop in a grid, rows, columns, whatever.

  • Drag them from over on the right hand side (vertical sub-menu for Layouts).
  • You can tweak the elements you plop down (css, etc.).

3) Add some "Shape" elements.

  • They are a little lower down in the right-hand vertical menu, under "Snippets".
  • Call them Test_Template and Test_Template_2 (notice the underscores).
  • Note: It should not matter that you haven't created the shape yet. As long as you name it correctly you will create it in a later step using Orchard.Templates (see below).
  • Click "Publish Now" when you are done.

4) Create a Template

  • Go to Admin > Templates
  • Call it Test_Template_2 (the first template just has some <p></p> tags).
  • Notice the (@this.WorkContext.CurrentUser.UserName); input this into the template.
  • Don't forget to click "Publish Now" when you are done.

5) Create a Page using your layout/template

  • When you are creating the page, just click the Test Layout under the "Use existing layout" drop down list.
  • Don't forget to click "Publish Now" when you are done.

6) Navigate to your page to view

  • The current user displays in the shape we created (the @this.WorkContext.CurrentUser.UserName we input earlier in the template).
  • This is great if you can't access your tools to do this otherwise.
  • Next up for me is figuring out how to display data that the user inputs (using Projections I imagine).
  • Ignore the references to some of the Orchard.Layouts .cshtml files, I am just messing around to see the boundaries of what is displayed (I am planning on creating a shell around that using ~/Themes).
Mar 11, 2015 at 11:12 PM
CAVEAT: There are so many nuggets of information just in this discussion list on codeplex. I've posted on two separate threads today, and after researching stuff I found a lot of answers to my questions on the codeplex discussion list for orchard. Now, I am no expert. What I found helped me in my situation. I don't know if its the best way, but it works. So, maybe this "tip" will be helpful to some.