Jump to content

Is it possible to hook into PageImages?


thomas
 Share

Recommended Posts

Hello,

I was wondering if it was possible to hook before PageImages url is given, so I can provide a default image if an image is missing? I have about a hundred cases where I need to check for count($page->image), so I thought maybe a module could do this?

Thanks!

thomas

Link to comment
Share on other sites

Not an easy one, as url isn't hookable in this case. And it also wouldn't be the right place. Since if there's no image ... $page->image will not be an object to start with.

But you could make a module function that you use to output images and do your checks there and return a blank.jpg or whatever if there's no image(s).


// autoload module

public function init(){
  // add 
  $this->page->addHook("renderImage", $this, "renderImage");
}
public function renderImage($event){
  $page = $event->object();
  $imagefield = $event->arguments[0];
  if($page->template == "admin") return;
  if($page->$imagefield) return "<img src='{$page->$imagefield->url}'/>";
  return "<img src='{$this->config->urls->templates}img/noimage.gif'/>";
}

Then use it

echo $page->renderImage("image");

Or just use an include function.php, as Ryan suggested in the other thread to do such things.

  • Like 1
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...