Error on Local Server

Hello,

I get an error “syntax error, unexpected end of file” but just on my local host. Not sure if this has something to do with the php version, already changed it to several versions but still get the same error. On the webhost everything works fine, cannot see anything wrong in this template:

    <?php

$teaser_list = $page->teaser()->toStructure();
$i = 0;
$j = 0;

function getAct($id) {
  
     $value = '';  
    
         if ($id == 1) {
         $value = 'active';
             
     } 
	
    return $value;
}

?>

<?php snippet('header') ?>


<div class="container-fluid space_bottom2">
    <div class="row">
        
    <div class="col-md-12 col-lg-9 del_pad">
    <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
    <?php foreach($teaser_list as $num): $j++; ?>
    <li data-target="#carouselExampleIndicators" data-slide-to="$j" class="<?= getAct($j) ?>"></li>
    <?php endforeach ?> 
  </ol>
  <div class="carousel-inner ">
    <?php foreach($teaser_list as $entry): $i++; ?>
    <div class="carousel-item <?= getAct($i) ?>">
      <img class="d-block w-100" src="<?= $entry->bild()->toFile()->url() ?>" alt="<?php echo $entry->bild()?>">
    </div>
     <?php endforeach ?> 
  </div>
</div>   
    </div>
        <div class="col-md-12 col-lg-3 right_box">
            <h3><span class="white"><?= $page->title() ?></span></h3>
            <div class="tage_bar"><?= $page->tage() ?> Tage Reise</div>
            <div class="space_top3">
            <span class="white"><?= $page->einleitung() ?></span>
            </div>
        </div>
    </div> 
    <div class="row">
        
    <div class="col-md-12 col-lg-9 landing_content">
            <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
  <li class="nav-item mobile_space3">
    <a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true"><?= $page->sec1_h() ?></a>
  </li>
  <li class="nav-item mobile_space3">
    <a class="nav-link" id="pills-profile-tab" data-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false"><?= $page->sec2_h() ?></a>
  </li>
  <li class="nav-item mobile_space3">
    <a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false"><?= $page->sec3_h() ?></a>
  </li>
  <li class="nav-item mobile_space3">
    <a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-more" role="tab" aria-controls="pills-more" aria-selected="false"><?= $page->sec4_h() ?></a>
  </li>
</ul>
<div class="tab-content space_top5" id="pills-tabContent">
  <div class="tab-pane fade kirby_text show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab"><?= $page->sec1_t()->kirbytext() ?></div>
  <div class="tab-pane fade kirby_text" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab"><?= $page->sec2_t()->kirbytext() ?></div>
  <div class="tab-pane kirby_text fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab"><?= $page->sec3_t()->kirbytext() ?></div>
  <div class="tab-pane kirby_text fade" id="pills-more" role="tabpanel" aria-labelledby="pills-more-tab"><?= $page->sec4_t()->kirbytext() ?></div>
</div>
    <div class="space_top2 info_holder"><h3><?= $page->info() ?></h3></div>
    <div class="space_top2 kurz_info">
        <div class="container">
            <div class="row">
                <div class="col-6 col-lg-3 mobile_space3"><div class="white ">Termine</div><span class="dark"><?= $page->termine() ?></span></div>
                <div class="col-6 col-lg-3 mobile_space3"><div class="white">Buchungscode</div><span class="dark"><?= $page->buchungs_id() ?></span></div>
                <div class="col-6 col-lg-3 mobile_space3"><div class="white">Reisepreis p.P.</div><span class="dark"><?= $page->preis() ?></span></div>
                <div class="col-6 col-lg-3 mobile_space3"><div class="white">Reisestatus</div><span class="dark"><?= $page->reise_status() ?></span></div>
            </div>
        </div>
    </div>
    <div class="space_top5"><?= $page->hinweis()->kirbytext() ?></div>
        <div class="space_top5 kurz_info2">
        <div class="container">
            <div class="row">
                <div class="col-12 col-lg-7 mobile_space2 center_mobile">
                    <div class="white"><h5>Wir freuen uns auf Ihre Anfrage nach Madagaskar.</h5></div></div>
                <div class="col-12 col-lg-5 text-center"><div class="white"><a href="<?php echo url() ?>/anfrage"><div class=" btn_anfrage" >Anfragen</div></a></div></div>
            </div>
            </div>
        </div>
    </div>


        
        
<div class="col-md-12 col-lg-3">
            <div class="landing_right">
                <img class="rounded-circle" height="100" src="<?php echo url('assets/images/hasina.jpg') ?>">
                <div class="space_top3">
                <h6>Hasina Samoelinanja</h6>
                <p>Madagaskar hautnah und authentisch! Unser Ziel ist es, der Natur und den Menschen auf unaufdringliche Art so nah wie möglich zu kommen.</p>
                 <a href="mailto:hasina@petit-prince.reisen"><button type="submit" class="btn submit_btn" name="submit" value="Submit">Kontakt</button></a>
                </div>
                <div class="banner space_top2">
                    <a href="<?php echo url() ?>/<?= $page->banner_link() ?>"><img class="" width="220" src="<?= $page->image("banner.jpg")->url() ?>"></a>
                </div>
            </div>
</div>
        
    </div>
</div>

<?php snippet('footer') ?>

Looks like something is not correct in this part:

<div class="carousel-inner ">
    <?php foreach($teaser_list as $entry): $i++; ?>
    <div class="carousel-item <?= getAct($i) ?>">
      <img class="d-block w-100" src="<?= $entry->bild()->toFile()->url() ?>" alt="<?php echo $entry->bild()?>">
    </div>
     <?php endforeach ?> 
  </div>

Can’t see an error in that file, apart from one thing you should not do but that’s not causing the error.

In this line

<?= $page->image("banner.jpg")->url() ?>

you should check if the image exists before you call the url() method.

Also, there shouldn’t be empty spaces at the beginning of the file before your opening <?php tag.

Thanks. How can I check if the file exist? But yes its not causing the error, the file exists.
I shared a snippet where the error come from but I don’t understand why

<?= ($image = $page->image("banner.jpg")) ? $image->url() : '' ?>

When I remove this line it works: <?= $entry->bild()->toFile()->url() ?>

But what’s wrong with it?

The same as mentioned above, never call a class method without making sure you have an instance of that class.

I keep repeating this in every third post I think (or at least it feels as if I do it that often), we also have it in the docs… :wink:

That was the problem, even it makes no sense because the images are their LoL

Thank you. Will use it in the future