Speed Posted October 6, 2016 Share Posted October 6, 2016 Hi Everyone, As much I am trying to understand the core of PW, I've been following few other tuts including Joss Sanglier's basic webpage tutorial. It was easy to follow except the part where I could not solve problems with image size. Here's link https://processwire.com/docs/tutorials/simple-website-tutorials/the-basic-website/page5 see the "Writing the Panel Code" part. Here's my code... using KubeCSS foundation. <?php include("./includes/head.inc"); ?> <div class="row centered"> <div class="col col-6"> <div class="content"> <h1><?php $page->title; ?></h1> <?php echo $page->ckeditor_1; ?> </div> </div> </div> <?php $panels = $pages->find("template=basic-page"); foreach($panels as $panel);{ ?> <div class="panels" style="background-color:<?php echo $panel->color_picker; ?>"> <div class="row centered"> <div class="col col-8"> <div class="content"> <h2><?php echo $panel->title; ?></h2> <?php echo $panel->ckeditor_2; ?> <p class="readmore"><a href="<?php echo $panel->url; ?>">Read More</a></p> </div> </div> <div class="col col-8"> <div class="content"> <?php if($panel->image_single){ echo "<img src='{$panel->image_single->size(400,200)->url}' alt='{$panel->image_single->description}'>"; } ?> </div> </div> </div> </div> <?php } ?> <?php include("./includes/scripts.inc"); include("./includes/foot.inc"); ?> ... and got error... I've "debugged" part of code and noticed echo "<img src='{$panel->image_single->size(400,200)->url}' alt='{$panel->image_single->description}'>"; The size(400,200) is the problem! Can anyone help me resolve this issues. Thanks in advance Link to comment Share on other sites More sharing options...
adrian Posted October 6, 2016 Share Posted October 6, 2016 Is image_single set to a max of 1 image on the details tab? 1 Link to comment Share on other sites More sharing options...
Speed Posted October 6, 2016 Author Share Posted October 6, 2016 Haha You rock! Care to explain what exactly it does? Link to comment Share on other sites More sharing options...
adrian Posted October 6, 2016 Share Posted October 6, 2016 5 minutes ago, Speed said: Haha You rock! Care to explain what exactly it does? Ah sorry - have a good read through this: https://processwire.com/api/fieldtypes/images/ But in essence, if it's not set to 1 then it returns an array of images, so you can either set to 1, or use this to get the first image. You can also use last() or eq(n) to specify a specific image. $panel->image_single->first()->size(400,200)->url 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted October 6, 2016 Share Posted October 6, 2016 The images field by default does return a list of images and you cannot call size() on a list, but only on a single image. By using the settings of the field you can alter that behavior to only return a single image directly. 2 Link to comment Share on other sites More sharing options...
Speed Posted October 6, 2016 Author Share Posted October 6, 2016 It all make sense now! Thank you for guys for clarification. 3 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