This project is read-only.

Notifier outsides of admin area

Topics: Customizing Orchard, Writing modules
Sep 14, 2011 at 9:29 PM

Hi all!

Is there a convenient way to display notifications on the "outer" areas of Orchard? I see that notifications are added to the layout shape in the AdminNotificationFilter and displayed in the "messages" zone (set in the theme "TheAdmin"). But AFAIK there is no built in way to display them in other areas as the admin page without writing our own code much like it is already done. Or am I missing something?

P.S. Actually a notification is created, but never displayed (I suppose, as the action shorty after makes a redirect) in CommentController/Ln 58

Sep 23, 2011 at 9:26 AM

Although not achieved with the notifier, but something similar is made in the Orchards.Users module if for example the user mistypes the password: the ValidationSummary is displayed.

Sep 23, 2011 at 11:22 AM

I had the same problem. I solved it by adding the Zone to my Layout, now i get notifications displayed there, if there are some notifications.

<div id="layout-Content">  
   <div id="main" role="main">
    @if (Model.Messages != null) 
     <div id="messages" class="zone">
Sep 26, 2011 at 12:02 PM

Thanks, that is great. I was thinking about a solution without modifying the theme (as the functionality would be part of a module). I suppose this is only possible then with injecting the message shape into the layout in runtime in the handler.

Sep 27, 2011 at 8:52 AM
Edited Sep 27, 2011 at 8:53 AM

Well yeah, you could also alter the notify itself and make it inject into another zone.

But then again, i figured, why change a running system ... Doesn't hurt me if i have that zone in my Theme, it's only visible if there is some message anyway and it doesn't bother me otherwise. Also, you would need another zone to inject to anyway, or you use an existing one and risk, that a notification "moves" your content around. In my case, it's displayed under content, and all it does for me, is move my footer bar down, which isn't static anyway, due to different content lengths.

There's an example of the Notfier, however i didn't take the time to figure out, where it's burried in Orchard itself.

My guess would be, that you have to look for this in Orchard:

             var messagesZone = _workContextAccessor.GetContext(filterContext).Layout.Zones["Messages"];
            foreach(var messageEntry in messageEntries)
                messagesZone = messagesZone.Add(_shapeFactory.Message(messageEntry));

and alter it.

Sep 27, 2011 at 8:32 PM

Yeah, I was exactly thinking about this. Actually it is also a nice example of dynamically injecting shapes into the layout.