Jump to content

Error with Image Size from Joss Sanglier Tuts


Speed
 Share

Recommended Posts

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...

Capture.JPG

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

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
  • Like 3
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...