n0sleeves Posted February 13, 2013 Share Posted February 13, 2013 Hi all. Very new to ProcessWire. I am excited about learning it and am currently trying to switch over a MODX site at this very moment. I am reading the API docs and as much of the forum as possible, however I am lost I have an image fieldtype named, "col1Image". I uploaded a photo and now want to display on the site. This is how I referenced it: <img src="<?php echo $page->col1Image; ?>"> However, I know that only is displaying the image/file name and I need to reference the complete path to it. Can you help a newbie out on this one please? I can't seem to find a clear answer. Also, even though I've read the docs numerous times, in regards to paths and urls, I'm still not "getting it". Is there another reference/guide/forum post that's explains things even simpler? For me to not be able to figure out how to reference an image source's path is pretty humiliating I have managed to reference my stylesheet and some hardcoded images, but that's about it. Thank you so much everyone. Link to comment Share on other sites More sharing options...
Joss Posted February 13, 2013 Share Posted February 13, 2013 Hi and welcome! $page->col1Image->url Is what you are after. That will come complete with the path. And you are welcome to keep asking questions here without feeling daft - every body does and everybody tries to answer them too! Joss 1 Link to comment Share on other sites More sharing options...
Joss Posted February 13, 2013 Share Posted February 13, 2013 Oh, I should add a couple of other bits! If you set your image file so it can only have one image, then you can treat it as a single result as I just did above. However, if you set it for more than one image (or any number by leaving it set at 0) then it will produce an array. So you will need to treat it as such and either loop through the images or just grab the first: Read this post by Ryan (or God, as we know him) http://processwire.com/talk/topic/81-images/ 1 Link to comment Share on other sites More sharing options...
n0sleeves Posted February 13, 2013 Author Share Posted February 13, 2013 Joss, YES!!! THANK YOU!! That worked! It's confusing to me why "->url" would come AFTER the image and not before as in: "url->col1Image". Can you explain the logic there how it works? Just checked out the array example. Thank you for that. That too is something I would prob. have asked in the future. Link to comment Share on other sites More sharing options...
Soma Posted February 13, 2013 Share Posted February 13, 2013 First there was an object. It was so lonely and had no home so we gave him an url. It was very happy and lived long until someone came and deleted it. 3 Link to comment Share on other sites More sharing options...
Joss Posted February 14, 2013 Share Posted February 14, 2013 Okay, Soma just gave an answer that was almost as silly as the one I was going to give! I think the logic is: $page - that is the current page $page->image_field - that is the name of our image field belonging to the current page $page->image_field->url - that is the url belonging to the image field belonging to the current page and of course $page->image_field->description - that is the description belonging to the image field belonging to the current page where we started the conversation. So, there is a logic to it! 1 Link to comment Share on other sites More sharing options...
n0sleeves Posted April 13, 2013 Author Share Posted April 13, 2013 Thanks guys. I have learned a lot since this post started. I seem to have a new problem regarding an image's path not referencing. This is a new project so the names have changed a bit, but I didn't want to start a new topic. I am referencing a single image field called column1_image. The image tag is coded below. That should display the image but it's not. <img src="<?php echo $page->column1_image->url; ?>" class="border"> In the site source code, it references the files folder but doesn't display the image name at the end. The image is in the files folder too. <img src="/anything_pw/site/assets/files/1/" class="border"> I really wanted to figure it out on my own since it's probably me doing something wrong, but I either need sleep or am losing brain cells BTW, for other newbies, "anything_pw" is my project's folder name.Thank you. Link to comment Share on other sites More sharing options...
adrian Posted April 13, 2013 Share Posted April 13, 2013 Is there any chance that you have output formatting turned off for the page? eg $page->of(false) Link to comment Share on other sites More sharing options...
Macrura Posted April 13, 2013 Share Posted April 13, 2013 does your error log show anything? Are you sure there is an image uploaded, and the api is considering it a single file (max images 1)? have you tried it on other pages, other templates... might help to narrow down the issue... Link to comment Share on other sites More sharing options...
n0sleeves Posted April 13, 2013 Author Share Posted April 13, 2013 Is there any chance that you have output formatting turned off for the page? eg $page->of(false) I don't know what that means. I'll look up output formatting, unless you would like to explain for me? :) Would love to know. Thank you. does your error log show anything? Are you sure there is an image uploaded, and the api is considering it a single file (max images 1)? have you tried it on other pages, other templates... might help to narrow down the issue... It works!!! I didn't set Max Images to 1. Thank you!! Just for the heck of it, how would I know/check the image is uploaded? By checking the files folder, correct? Link to comment Share on other sites More sharing options...
adrian Posted April 13, 2013 Share Posted April 13, 2013 You can read more about output formatting about half way down this page:http://processwire.com/api/variables/page/ But, in your particular situation, Soma explains it well here: http://processwire.com/talk/topic/2917-command-line-script-file-api-not-performing-same-as-on-website/?p=28697 "Image field is always an array, it's just that page output formatting does change it so in template files you get an object if the image field is set to max 1 item. So if output formatting is off it's always treated as an array, disregarding the field settings." If you have it set to false, or you have max images set to anything but '1' then you need to do one of the following: $page->column1_image->first()->url $page->column1_image->eq(3)->url $page->column1_image->last()->url 1 Link to comment Share on other sites More sharing options...
Macrura Posted April 14, 2013 Share Posted April 14, 2013 Just for the heck of it, how would I know/check the image is uploaded? By checking the files folder, correct? i was just saying to make sure that the page you were testing on actually had some images 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