Jump to content

Filtering the list of notices


twols
 Share

Recommended Posts

Hello, guys!

I'm trying to display the list of notices, but unfortunately there are more informations that I would like to show:

Quote

 

You was successfully logged out!

Compiled file: /site/templates/logout.php <- how can I filter this??

 

The class of the notice seems to be always 'Session'. But sometimes also 'FileCompiler'..

Here is the code:

<?php if(count(ProcessWire\wire('notices'))): ?>
<div id="messages">
<?php foreach (ProcessWire\wire('notices') as $notice): ?>
  <?php

    if($notice->class != 'Session') {
      continue;
    }

    if ($notice instanceof NoticeError) {
      $class = "error";
    } else {
      $class = "information";
    }
  ?>
  <div class="<?php echo $class; ?> <?php echo $notice->class; ?>"><?php echo $notice->text; ?></div>
<?php endforeach; ?>
</div>
<?php ProcessWire\wire('session')->removeNotices(); ?>
<?php endif; ?>

 

Link to comment
Share on other sites

You can filter the notices with a hook before Page::render in /site/ready.php

The file compiler notices are useful information so probably sensible to filter these notices only for non-superusers.

$this->addHookBefore('Page::render', function($event) {
    $user = $this->user;
    if(!$user->isSuperuser()) {
        $notices = $this->notices;
        $notices->not("class=FileCompiler");
        $notices->not("text~=Compiled file");
    }
});

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...