Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Extending the "messages" positions

edited March 2011 in Vanilla 2.0 - 2.8
Vanilla allows messages to be added to various parts of pages, namely the side column and the top of the main content area. Is there a simple way to extend these areas in an arbitrary way, perhaps through a theme?

My current need is to be able to put editable blocks in the footer of the theme, but cannot find any obvious way to do this. Creating my own arbitrary "message positions" in the footer would allow me to do this without a lot of effort.

Would that be a good approach, or am I missing a "edit footer text" link somewhere in the dashboard?


  • Options
    Now I have come to look at this, there are events that allow the position lists to be extended in a custom module. I just need to work out how to use that custom information to store messages and then pull them out into various places in my theme. I assume it has something to do with assets, but it is hard work reverse-engineering this thing.
  • Options
    Turns out to be as easy as adding a new message position (I created positions "Foot1" to "Foot4" using the hook mentioned above) then rendering it in your theme template like this:


    That's it! Wrap a class around it to allow for styling and you have custom content areas that can be changed at will.
  • Options
    May be some ready to run solution? Or example?
  • Options
    edited March 2011
    In case this is useful to anyone else, this is what I added to a custom plugin (I have a plugin just for adding custom overrides):

    public function MessageController_AfterGetAssetData_Handler(&$Sender) { $Sender->EventArguments['AssetData']['Foot1'] = 'Footer column 1'; $Sender->EventArguments['AssetData']['Foot2'] = 'Footer column 2'; $Sender->EventArguments['AssetData']['Foot3'] = 'Footer column 3'; $Sender->EventArguments['AssetData']['Foot4'] = 'Footer column 4'; }

    That function then adds four new message positions to allow me to add content. These show up in the dashboard->messages->add popup.

    In my theme I have four columns defined, each of which pulls messages as content from one of the four message asset areas, e.g. in the theme views/default.master.php:

    <div id="Foot"> <div class="column1"><?php $this->RenderAsset('Foot1'); ?></div> <div class="column2"><?php $this->RenderAsset('Foot2'); ?></div> ...etc </div>

    And that is it. Apart from styling, this now gives me four areas in the footer where I can add more information that can be be changed regularly through the admin screens.
  • Options
    So, first part allow you to define new positions.
    And you are rendering them later in your theme in necessary positions. Right?
    It can be also very interesting to allow messages to be targeted at very specific places and specific users (for new users only, on first visit of category, etc).
  • Options
    edited March 2011
    Yes - I think the terminology is "assets" rather than positions, but an asset is a collection of things (modules) that are positioned somewhere in a template.

    It kind of makes sense for these assets to be declared by the theme, since it is the theme that will display them. I'm not sure if that is possible. WordPress supports that, with each theme able to define the areas where widgets (ie. modules for Vanilla) can be placed. The messages in Vanilla are just modules, so far as I understand, just like the "Start a new discussion" button and the list of categories are modules.

    The messages controller also allows the list of pages where each message will appear to be extended. I didn't need to do that in this case, since the footer messages I am displaying are displayed on every page and are not dismissable.

    Displaying messages to new users only is supported already - just set the message to allow it to be dismissed. Once a user has read it, they can dismiss it, and will not see it again.

    Targeting at individual users, I suspect, would be more an extension of the private conversation features, kind of extended so that certain (flagged?) conversation messages can be brought out to other places in the page or pages.

    I have only tried displaying these assets in the master page template. I suspect it won't work in the other views (or would be a little unpredictable, working or not depending upon the order in which the controllers declare assets and render their bits of HTML).
  • Options
    LincLinc Detroit Admin
    The controllers are set up to allow you to store things like modules and strings of HTML into "Assets". Then the renderer looks to match what's in the template with what's stored in the corresponding controller asset.

    For instance, when you make a View, you're really just adding stuff to the 'Content' asset, it's just Vanilla doing it automatically. Similarly you have the Head, Foot, and Panel assets typically, and you can create any others you like.

    If you create assets in the controller that don't exist in the template, they simply never appear. If you put assets in the template but the controller doesn't add anything to them, they output blank.

    I bet you can render assets in normal views too, but it could get confusing.
  • Options
    I think it could be good to make short docs about this.
    May be turning or making small plugin as good commented example.
Sign In or Register to comment.