CBE Posted August 3, 2021 Share Posted August 3, 2021 Hello. I've setup a page (without a php file) based on a template with some fields. I am able to render the text fields content from another page (an included php file): $pages->get('/general-information/')->phone_number However, I am unable to render the image field content $pages->get('/general-information/')->front_image->url I got an error message (method call on null) The image field is set to allow only one value, and to allow html entity characters 1 Link to comment Share on other sites More sharing options...
Andy Posted August 3, 2021 Share Posted August 3, 2021 @CBE The fact is that the image field can be either for a single picture or for an array of pictures. Check how you set the image field for front_image. Read more about this in the documentation. But in short. For a single picture, the call will be like this: $image = $page->single_image; if($image) echo "<img src='$image->url'>"; For an array of pictures, you can choose the first one: $image = $page->images->first(); if($image) echo "<img src='$image->url'>"; Look to Maximum files allowed and Formatted value Link to comment Share on other sites More sharing options...
CBE Posted August 3, 2021 Author Share Posted August 3, 2021 The examples provided by @Andy works seamlessly when the page corresponds to the template (using $page). However I'm not able to render the image field content on another page (using $pages). As I said before the image field is set to allow only one value, and to allow html entity characters. Link to comment Share on other sites More sharing options...
Andy Posted August 4, 2021 Share Posted August 4, 2021 @CBE The method of accessing other pages certainly works. Perhaps you have an error somewhere or access to the page is denied. There is little information on this here. Try to break the task into steps, check it step by step. $my_page = $pages->get('/general-information/'); if($my_page){ $my_img = $my_page->front_image; if($my_img){ $my_url = $my_img->url; }else{ echo "Image not acces"; } }else{ echo "Page not acces"; } Or just see what PageArray returns to you $my_page = $pages->get('/general-information/'); if($my_page) print_r($my_page); // use var_dump($my_page) for bit more info 1 Link to comment Share on other sites More sharing options...
CBE Posted August 5, 2021 Author Share Posted August 5, 2021 It finally worked. I don´t know how. I was setting permissions everywhere. But when I started revoquing unusual permissions again, trying to figure out the cause of the issue, I ended with the code still rendering the url. So I don´t know. Maybe a cache issue on the ProcessWire side. Anyway, thanks @Andy I appreciate your help. 1 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