Forum

Thread tagged as: Question, Problem

Image not showing on pages

Hi, How to I get an image to show up so that it can be added to the page by the end user using the responsive image code? I have used the following code and added in to a template file called main_image.html in the content folder.

<img src="<perch:content id="mainimage" type="image" width="458" label="Image" />" alt="<perch:content type="text" id="alt" label="Description " required="true" help="Description of this image" title="true " />" srcset="<perch:content id="image" type="image" width="458" label="Image" density="2" /> 2x, <perch:content id="image" type="image" width="458" label="Image" density="3" /> 3x">
David Roberts

David Roberts 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You then need to use that template for a region. Add the following to your page:

<?php perch_content('Image'); ?>

Then reload the page in the browser. In the control panel you should see the new region. Click through and pick your new template as the template for that region.

Thanks for that.

I must be still doing something wrong because the image is not showing on the web site page. There is just a blank square with a ?.

Although the source code shows it to be their, there is some php code.

<div class="img-holder">
            <?php perch_content('Image'); ?>
<img src="/perch/resources/img01-1x-w458.png" alt="" srcset=" 2x,  3x">
</div>

So I have template/region/master page(s).

Template

<?php perch_content('Image'); ?>
<img src="<perch:content id="mainimage" type="image" width="458" label="Image" />" alt="<perch:content type="text" id="alt" label="Description " required="true" help="Description of this image" title="true " />" srcset="<perch:content id="image" type="image" width="458" label="Image" density="2" /> 2x, <perch:content id="image" type="image" width="458" label="Image" density="3" /> 3x">

Region

<div class="coloum">
    <div class="box-two">
        <div class="img-holder">
            <?php perch_content('main_image'); ?>

Master page

<?php   
    perch_layout('global/global.header', [
         'page_title'=>perch_pages_title(true),
    ]);

   perch_page_attributes([
      'template' =>'seo.html',
    ]);

   perch_layout('header.home');

   perch_layout('main.image');

   perch_layout('intro.box');

perch_layout('global/global.footer');
Drew McLellan

Drew McLellan 2638 points
Perch Support

You don't need to add

<?php perch_content('Image'); ?>

as you already have

<?php perch_content('main_image'); ?>

Ok, I will try that.

Your notifications are not working to me.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Email notifications from the forum? Thanks, we'll take a look. We moved to a new set of servers yesterday, so the queue may not be processing.

I got 6 notices at 6.33am today, not that I was up then, but they seem to be working again.

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

We've been chasing the queue through!

This still is not working! The image is not showing on the page, although in the source code shows that it is there. Not sure why <?php perch_content('Image'); ?> is showing, I am using <?php perch_content('main_image'); ?>

<div class="img-holder">
            <?php perch_content('Image'); ?>
<img src="/perch/resources/img01-1x-w458.png" alt="London Science Museum's difference engine showing some of the number wheels and the sector gears between columns" srcset=" 2x,  3x">
</div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Don't use <?php perch_content('Image'); ?> - you don't need it.

I am not that's why I don't understand that it is showing.

main.image.php is this

<div class="coloum">
    <div class="box-two">
        <div class="img-holder">
            <?php perch_content('main_image'); ?>

Source output is this

<div class="coloum">
    <div class="box-two">
        <div class="img-holder">
            <?php perch_content('Image'); ?>
<img src="/perch/resources/img01-1x-w458.png" alt="London Science Museum's difference engine showing some of the number wheels and the sector gears between columns" srcset=" 2x,  3x">
</div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you saved your region since changing the template? Compiled HTML is cached.

Yes, quite a few times.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is your browser caching?

Yes it is but I have tried other browsers as well.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. What else can you tell us?

Can you make any other edits to the file and see a change?

I deleted the image reload it renamed the image renamed the content page made no difference.

It is just an image on its own in a 'block' layout using Packery (https://packery.metafizzy.co) plugin like Masonry.

In the developer tools on chrome it give the info below.

Failed to load resource: the server responded with a status of 404 (Not Found) digitaleducation.education/:108 GET https://digitaleducation.education/2x 404 (Not Found) (index):1 GET https://digitaleducation.education/2x 404 (Not Found)

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Are you saying that you are seeing Perch tags if you View Source? I've just read through this and I don't understand what is being seen.

Can you confirm what you see if you do View Source in a browser?

This is what I see. No perch tags

</header>
        <main id="main" role="main">
        <div class="box-holder"><div class="coloum">
    <div class="box-two">
        <div class="img-holder">
            <img src="/perch/resources/london-science-museums-difference-engine-w458.png" alt="London Science Museum's difference engine showing some of the number wheels and the sector gears between columns" srcset=" 2x,  3x">
</div>
    </div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What size is the image you're uploading?

The size is 61kb.