Deciding display of custom part in Create\Edit views

Topics: Customizing Orchard, Writing modules
May 8, 2012 at 7:48 PM

Hi,

I created a custom part, that has a driver that renders buttons like Delete and Reject.

I also have a controller that handles the actions related to these buttons.

This  can then be welded to any Content type

My issue is that I want to only display these buttons in the Edit view and not in the Create view.

How can I do that?

Thanks!

Coordinator
May 8, 2012 at 7:56 PM

If you check src\Orchard.Web\Core\Contents\Views\Parts.Contents.Publish.SummaryAdmin.cshtml, you can find how to check the status of a content item.

May 8, 2012 at 9:57 PM

I checked the code. It is rendering different links depending upon whether a user has permissions to do those or a content's publish status.

I still couldn't get an idea, how could I check if the Model that is displayed is for Create then do not show Delete/Reject buttons but if it is for Edit, then show them.

Just a thought, can this be achieved somewhere in the driver for that part ?

Coordinator
May 8, 2012 at 10:14 PM

As I said, do it in your view using this code:

if(contentPart.HasDraft || contentPart.HasPublished) {

// you are in edit mode, because is already has a draft or a published version ... otherwise it's a new item

}

 

May 8, 2012 at 10:23 PM

Duhh..thanks, that makes sense :)

Coordinator
May 8, 2012 at 10:25 PM

By the way, seems you are working on a Workflow module. If so, might nice to get in touch, I have some design thoughts about that one. I want one in Orchard.