joer80 Posted February 13, 2017 Share Posted February 13, 2017 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 More sharing options...
louisstephens Posted February 13, 2017 Share Posted February 13, 2017 I am not sure what is going on in your case (I am sorry I dont have an answer). However, $page->BackgroundImage->url should return the pull path to the image. Link to comment Share on other sites More sharing options...
adrian Posted February 13, 2017 Share Posted February 13, 2017 This is the usual array of images problem - either add first()->url, or set the image field to only accept one image. 1 Link to comment Share on other sites More sharing options...
joer80 Posted February 13, 2017 Author Share Posted February 13, 2017 That is what I would have thought also, but it is set to "Single Item (Null if empty)" with 1 as the max images. Looks like it is returning an array no matter what I do. Link to comment Share on other sites More sharing options...
adrian Posted February 13, 2017 Share Posted February 13, 2017 Any chance you have output formatting turned off? Link to comment Share on other sites More sharing options...
joer80 Posted February 13, 2017 Author Share Posted February 13, 2017 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 More sharing options...
adrian Posted February 13, 2017 Share Posted February 13, 2017 Do a little experiment and dump or bd($page->of()); before your $event->message and see what you get. Link to comment Share on other sites More sharing options...
joer80 Posted February 13, 2017 Author Share Posted February 13, 2017 var_dump($page->of()); doesnt seem to do anything. If I take off the "->of()" it will print out the page info. Link to comment Share on other sites More sharing options...
adrian Posted February 13, 2017 Share Posted February 13, 2017 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? 1 Link to comment Share on other sites More sharing options...
joer80 Posted February 13, 2017 Author Share Posted February 13, 2017 I was able to use output buffering and get it to: result: bool(false) ob_start(); var_dump($page->of()); $result = ob_get_clean(); $event->message("result: " . $result); Link to comment Share on other sites More sharing options...
joer80 Posted February 13, 2017 Author Share Posted February 13, 2017 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 More sharing options...
adrian Posted February 13, 2017 Share Posted February 13, 2017 It's not a bug - when saving, output formatting has to be off. PS - you should get familiar with Tracy: bd($page->of()) is a lot easier than messing around with ob_start and var_dump 1 Link to comment Share on other sites More sharing options...
joer80 Posted February 13, 2017 Author Share Posted February 13, 2017 Ok, thanks for the tip! Link to comment Share on other sites More sharing options...
kongondo Posted February 13, 2017 Share Posted February 13, 2017 (edited) 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 February 13, 2017 by kongondo 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 13, 2017 Share Posted February 13, 2017 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 2 Link to comment Share on other sites More sharing options...
kongondo Posted February 13, 2017 Share Posted February 13, 2017 2 minutes ago, LostKobrakai said: Only if it's executed before or after template rendering, which is most of the time, but not always. Aah, good to know . 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now