How to alter a rendered view: Revision

Last updated by Steve Clay

I prefer not to override whole views if I can help it, as this like forking: you don't get upstream core/plugin changes. In Elgg 1.8+ you can alter views after they've been rendered with a plugin hook:

For example, this is how I remove breadcrumbs that have no links:

// arguments are 'view', the view name, and your handler callback
elgg_register_plugin_hook_handler('view', 'navigation/breadcrumbs', 'myPlugin_alter_breadcrumbs');

function myPlugin_alter_breadcrumbs($hook, $type, $returnValue, $params) {
    // $hook is 'view', $type is the view name, $returnValue is the string
    // output of the view, and $params['viewtype'] has the view type.

    if ($params['viewtype'] === 'default') {
        if (false === strpos($returnValue, '<a ')) {
            $returnValue = ''; // if no link, remove completely
        }
    }
    return $returnValue;
}

 

History