Getting Page record from widget

Topics: Customizing Orchard, Writing modules
Aug 26, 2012 at 7:11 PM

Hi All,

I added a text/HTML-flavor field to the Page ContentType. The purpose or that field is to add special links for each page so users will get a "Suggested Reading" list for further information -- similar to Wikipedia's "See Also" and "External Links" sections. 

However, I'm trying to display this field in a widget placed on the sidebar. Since almost every page on the site will have different links, I'd rather not use layers as it will become cumbersome and impossible for laypeople to add pages on their own. 

I have a Widget-Wrapper view for that purpose but I'm trying to figure out how to get a hold of the Page model (along with the custom field) from within the Widget wrapper. 

Thank you all in advance. 

 

-JJ

Aug 27, 2012 at 2:29 AM
Edited Aug 27, 2012 at 2:30 AM

If you're on Orchard 1.5 or greater you should be able to use a Placement.info file to place a part in a separate top-level zone.

 

<Match ContentType="Page" DisplayType="Detail">
  <Place Fields_Input-FieldName="/AsideSecond:1" />
</Match>
Aug 29, 2012 at 7:33 PM

Thanks Brandon. That worked.

One last question, how can I wrap it with a custom DIV or SPAN tag so I can format it easily?

Again, thanks a lot.

Aug 29, 2012 at 9:02 PM

Cool.  If the markup in the template isn't to your liking you can use an alternate to modify the html.  You can even use the same Placement.info file to specify your alternate if you want...

<Match ContentType="Page" DisplayType="Detail">
  <Place Fields_Input-FieldName="/AsideSecond:1;Alternate=Fields_Input_Custom" />
</Match>
Then just take the code from the old template paste into your new one Fields.Input.Custom.cshtml, and modify from there.  You don't have to use the Placement.info to specify alternates if you use the naming conventions, so that's up to you.  Here is more info on alternates:  http://docs.orchardproject.net/Documentation/Alternates