This project is read-only.

Question about external data and modules

Topics: Customizing Orchard
Jun 19, 2015 at 11:47 AM

I'm completely new to Orchard and I have been reading the documentation and following some of the code examples on the Orchard site.

However, I'm a little confused how I can use a module within the CMS and display it as part of page/layout/content type?

If I explain a little more. I have followed the "Building a hello world module" tutorial and this all works very well. I have then adapted it slightly to consume a WCF service and display that data on the page instead of the "Hello World" that is in the tutorial.

This is all good and works fine.

But, when I then go to the admin pages, whilst I can see the module and enable it, I can't see how I can use this module to put it in a page.

I'm assuming I need to create a ContentType/Part/Record and this can then handle the data, but I don't want to write the WCF data to the Orchard db, which is what it appears to be doing.

Is there something I'm missing or is there a way that I can use this module more effectively within the CMS?

Jun 20, 2015 at 10:57 AM
Modules themselves are not things you can put on a page, they simply provide all sorts of useful things such as content parts, filters, services, commands, etc.
So your assumption is correct: to put something on a page, you typically build your own content part that can then be attached to a content type (such as Page or maybe even a new widget type).

When implementing a content part, you are completely in control where you're getting your data from. Orchard doesn't read or write data from a part - this is all up to you, and data access is completely optional.

In your case, all you would do is create your content part class and derive it from ContentPart (not contentPart<TRecord>).
Next, you would implement your content part driver. You would probably access your WCF service from the Display method of your driver (and possible using the CacheManager or CacheService to cache the data for a while, unless it needs to show real time data).

No DB access required (unless perhaps you want to store some WCF configuration parameters as part of your content part that you'd like the admin user to be able to manage from the Orchard admin UI).
Jun 20, 2015 at 12:08 PM
That is awesome advice. Thanks Skywalker 😊
Jun 22, 2015 at 2:59 PM
So I've created a ContentPart
public class HelloWorldPart : ContentPart
        public int DocumentId
            get { return Retrieve<int>("DocumentId"); }
            set { Store<int>("DocumentId", value); }

        public string DocumentHeader
            get { return Retrieve<string>("DocumentHeader"); }
            set { Store<string>("DocumentHeader", value); }

        public string DocumentBody
            get { return Retrieve<string>("DocumentBody"); }
            set { Store<string>("DocumentBody", value); }

        public byte DocumentData
            get { return Retrieve<byte>("DocumentData"); }
            set { Store<byte>("DocumentData", value); }
Implemented a driver:
public class HelloWorldDriver : ContentPartDriver<HelloWorldPart>
        protected override DriverResult Display(HelloWorldPart part, string displayType, dynamic shapeHelper)
            return ContentShape("Home_Index", () => shapeHelper.Home_Index(
                DocumentHeader: part.DocumentHeader,
                DocumentBody: part.DocumentBody,
                DocumentData: part.DocumentData));
I've deliberately not implemented the WCF service yet, I just want to see the content part.

And enabled the module

But I can't see this "part" in the admin Ui of the site.

It almost seems like I need to have this stored in the db in some way so the CMS knows that it needs to be made available.

Or is there something else I need to do?
Jun 22, 2015 at 6:58 PM
One thing that comes to mind is: did you create a Migration class that defines your content part?
Jun 22, 2015 at 7:40 PM
I'm pretty sure I tried it with and without a migration class, but will double check again once I get back my PC.
I did get it working by implementing the record class and deriving the contentpart from it. And then in the driver I substituted the with my own service results.

However I get it working I will post the code here for those that want to know how...