Jump to content

Problems to call an image field


justnew77
 Share

Recommended Posts

Hello,

I follow the instructions on this site how to deal with Image fields:

I generateed an field with the Name "themeimage" as type IMAGE,

I put it to the template,

and I put this code to the template file:

if($page->themeimage) echo "<img src='{$page->themeimage->url}'>";

I load up an Image inside the page but the image do not apear?!

This is what it renders out:

 <img src='/dev/site/assets/files/1/'>
Link to comment
Share on other sites

This is a recurring issue for those new to PW. Your images field is by default set to handle more than one image, so you can either change it to only support one image, or you need to define which image from the field you want to display:

if($page->themeimage) echo "<img src='{$page->themeimage->first()->url}'>";

Or replace first() with last() or eq(n) where n is the number of the image in the order, starting with 0.

To change the image field to only support one image, go to the field's details tab and change Maximum files allowed to: 1

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