eze102 Posted September 4, 2015 Share Posted September 4, 2015 Hi - can someone explain to me why I can't modify image size with the following code? <? foreach($page->call_to_action as $cta) { $count++; $class = ($count == 2) ? "one_half last" : "one_half"; $img = $cta->image->size(300,300); echo "<div class='{$class}'> <a href='{$cta->call_to_action_url}' class='over'> <span>{$cta->overlay_title}</span> <p>{$cta->overlay_description}</p> </a> <a href='{$cta->call_to_action_url}'><img src='{$img->url}'</a> </div>"; } ?> Link to comment Share on other sites More sharing options...
horst Posted September 5, 2015 Share Posted September 5, 2015 Sorry, I don't get what you are asking for?! Can you explain a bit more what your code does or does not and what you want to be the result? Also I'm not sure, but the original image URL in the a-tag, shouldn't it be: <a href='{$cta->call_to_action->url}' ^^ = -> instead of _ ?? Link to comment Share on other sites More sharing options...
eze102 Posted September 5, 2015 Author Share Posted September 5, 2015 Yes, I'm sorry. That was not clear! I created a repeater field called "call_to_action" with a few subfields, including "overlay_title" , "overlay_description" , "image" , and "call_to_action_url". I wanted to iterate over the "call_to_action" fields and output them, which is working; I also wanted to resize the image in the image field, but that isn't working... even though I did: $img = $cta->image->size(300,300); Link to comment Share on other sites More sharing options...
horst Posted September 5, 2015 Share Posted September 5, 2015 Aha! You need to debug what your $cta->image really holds. [ ] check if the fieldname is correct (image or images or other?) [ ] check if the image field is set to single-mode, what is [ ] put a line into your code to inspect the value (see *1) *1) foreach($page->call_to_action as $cta) { $count++; $class = ($count == 2) ? "one_half last" : "one_half"; $img = $cta->image->size(300,300); // debug $img: echo "<pre>\n\n"; var_dump($img); die('RIP :: ' . __FILE__ . ':' . __LINE__); echo "<div class='{$class}'> <a href='{$cta->call_to_action_url}' class='over'> <span>{$cta->overlay_title}</span> <p>{$cta->overlay_description}</p> </a> <a href='{$cta->call_to_action_url}'><img src='{$img->url}' /></a> </div>"; } BTW: in your code the img tag is unclosed (/>), and your code does not check if an image is really set for each repeater item. Or is the image field set to be required in the template? 2 Link to comment Share on other sites More sharing options...
eze102 Posted September 6, 2015 Author Share Posted September 6, 2015 Thank you! I still can't seem to access the size property of the image though. Fieldname is correct and image is in single mode. And when I add your debug code, I get like 5000 lines of output in the browser that I can't understand (I'm not very experienced with PHP). The code does not just stop the file and show the img value, it shows tons of lines of code... Link to comment Share on other sites More sharing options...
eze102 Posted September 6, 2015 Author Share Posted September 6, 2015 Actually, now none of the calls to $cta properties are working, except: $cta->call_to_action_url Link to comment Share on other sites More sharing options...
eze102 Posted September 6, 2015 Author Share Posted September 6, 2015 Is there something wrong with my code in general? Link to comment Share on other sites More sharing options...
eze102 Posted September 10, 2015 Author Share Posted September 10, 2015 Welp, seems like the only way to resize the image was by resizing the container in CSS! 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