wes Posted February 27, 2013 Share Posted February 27, 2013 Hi All, I'm trying to access some files in a PW site by using a command line script. For some reason certain file properties (as defined in the cheatsheet) aren't available on images inside of a repeater field, or perform unexpectedly. Example below: include("./root/index.php"); foreach($wire->pages->get("/my/page/path/")->the_repeater as $item){ echo $item->my_image; // prints only the file name, no path (expected) echo $item->my_image->url; // prints directory the file is in; e.g. '/site/assets/files/3205/' (unexpected, b/c this would normally give full URL to file when using through my templates) echo $item->my_image->filename; // what I really want to use, but prints nothing, just a blank line echo $item->my_image->ext; // prints nothing, just a blank line echo $item->my_image->width; // prints nothing, just a blank line } Any ideas? Thanks! Link to comment Share on other sites More sharing options...
Soma Posted February 27, 2013 Share Posted February 27, 2013 Looks like outputFormatting symptom. Try using it as array and use $item->my_mage->first->url. 1 Link to comment Share on other sites More sharing options...
wes Posted February 27, 2013 Author Share Posted February 27, 2013 Looks like outputFormatting symptom. Try using it as array and use $item->my_mage->first->url. Hmm, doesn't print anything. I would think that 'first' wouldn't be accessible because $item->my_image should be a PW file object ($item being an item from the repeater field). Link to comment Share on other sites More sharing options...
wes Posted February 27, 2013 Author Share Posted February 27, 2013 Ah, fixed it. You were right, it was something about output formatting. Doing a $item->setOutputFormatting(true) right before the echo statements did the trick. Thanks, Soma. Link to comment Share on other sites More sharing options...
Soma Posted February 27, 2013 Share Posted February 27, 2013 I'm not sure inside repeaters I think there's still some obscure things happening. Image field is always an array, it's just that page output formatting does change it so in template files you get an object if the image field is set to max 1 item. So if output formatting is off it's always treated as an array, disregarding the field settings. I think in case of a bootstrap there's no output formatting on I think. Since repeaters are pages attached to the page I think it may change something or not if you ad // short syntax of setOutputFormatting() $item->of(true); and this doesn't work? $item->my_mage->first()->url 1 Link to comment Share on other sites More sharing options...
wes Posted February 27, 2013 Author Share Posted February 27, 2013 Image field is always an array, it's just that page output formatting does change it so in template files you get an object if the image field is set to max 1 item. So if output formatting is off it's always treated as an array, disregarding the field settings. I think in case of a bootstrap there's no output formatting on I think. That's good to know. Forgot about the fact that image fields can have multiple items, so by default it would make sense to be an array. Thanks! 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