Jump to content

->url on image not giving full path, only folder with no filename


joer80
 Share

Recommended Posts

When I do $page->BackgroundImage->url it gives the path without the filename.  Is that normal?  I was thinking it gives both.

If I do  $page->BackgroundImage->url . $page->BackgroundImage I can get it to show both.

What am I doing wrong?

Thanks!

Link to comment
Share on other sites

I do further down the page.  This is the flow.

addHookBefore (save)

      $event->message("background-image: " . $page->BackgroundImage->url);
     //Gives  background-image: /site/assets/files/1312/

addHookAfter (save)

     setOutputFormatting(false);

(save a different page) 

Link to comment
Share on other sites

Well, that's weird - here it returns true or false.

Anyway, we are getting off track. Either turn on output formatting before $event->message, or simply add first() before url and you should be fine. Does that work or not?

  • Like 1
Link to comment
Share on other sites

I am in a module that is hooking before page save so maybe it would be best if I leave output format off?  I am wondering if processwire is expecting that?  

I dont mind treating it like an array as long as it is expected behavior and not a bug that will be fixed later!

Thanks for all your help!

Link to comment
Share on other sites

1 hour ago, joer80 said:

I am in a module that is hooking before page save so maybe it would be best if I leave output format off?

Actually, output formatting is always off in a module. If output formatting is off, Image fields will always return an array, no matter your settings. So...first(), last(), eq()....are your go to guys...

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

4 minutes ago, kongondo said:

Actually, output formatting is always off in a module.

Only if it's executed before or after template rendering, which is most of the time, but not always. That's why I go with this in places, where I cannot be sure about the state of output formatting:

$page->getUnformatted('image')->first()->url

 

  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...