Citytech Tester Posted June 10, 2015 Share Posted June 10, 2015 Hello all I am new to processWire. I have created a field "banner" from setup>Fields>Add New and assigned that for home page. When addin content for home page from Pages>home>edit i have uploaded two images for the field banner. But none of the images are displaying in front end. Even <?php print_r($page->banner);?> is showing nothing in processwire_root\site\templates\_main.php file. I am very new to processwire. Please guide me how can i display my newlly added field values in front end. Link to comment Share on other sites More sharing options...
Macrura Posted June 10, 2015 Share Posted June 10, 2015 Hi and welcome to the forum! if you are using _main.php, that sounds like you are outputting $content; so you have to add your output to that var. if you are a beginner and using the beginner profile, then you would only need to echo your field. Sounds like your field is multi image, so you'll need to foreach that and output your markup in the loop, for each image. Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 10, 2015 Author Share Posted June 10, 2015 Hello Macrura Thanks for your reply. Yes my fied is multiple image field. A inamge field was already added for my home page. Anf in front end when i am doing <?php print_r($homepage->images);?>it is working fine. but for my custom field it is not working. In processwire_blog\wire\modules\AdminTheme\AdminThemeDefault\default.php there is if($page->body) echo $page->body; in line number 93 which is ftching all the contents added for a perticular page but in front end echo $page->body not displaying all the contents. It is displaying all except my custom fields Please tell me how can i get that field value. Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 10, 2015 Author Share Posted June 10, 2015 Hello Macrura, I have added a field named banners which is exactly like images field which is already added for home page and basic page. When i am editing the home page in admin section i can view the banners field and can upload images for this field just like the images field. But in front end processwire_root\site\templates\_main.php file when i am writing <?php if(count($homepage->banners)) { $image = $homepage->banners->getRandom(); $thumb = $image->size(606, 372); echo "<p><img src='$thumb->url' alt='$thumb->description' /></p>"; } ?> this is showing nothing. Please help. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 10, 2015 Share Posted June 10, 2015 $page->body does only display the body field. There's nothing that would automatically display all fields of a page in a reasonable manner. You need to layout the presentation of the different fields by yourself. $page->body fetches the body textarea, while $page->banner will get you your banners. Maybe you should have a look at the different tutorials here: http://processwire.com/docs/tutorials/ Especially the one about structuring template files. Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 10, 2015 Author Share Posted June 10, 2015 (edited) Hello LostKobrakai, Thanks for your reply. I have done <?php if(count($homepage->banners)) { $image = $homepage->banners->getRandom(); $thumb = $image->size(606, 372); echo "<p><img src='$thumb->url' alt='$thumb->description' /></p>"; } ?> in template. Still i can't view any images under banner field. Edited June 10, 2015 by LostKobrakai Edited the code box in. Please use these in the future. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 10, 2015 Share Posted June 10, 2015 Is $homepage defined anywhere? It's not a variable available by default. Most of the time users use this in their _init.php, which can be prepended to all templates: $homepage = $pages->get("/"); Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 11, 2015 Author Share Posted June 11, 2015 Hello LostKobrakai, Thanks for your reply. The problem has been sorted out. Thanks for your help. Hello LostKobrakai, I have another question. Will you please tell me how can i add a contact from in my website? Link to comment Share on other sites More sharing options...
Peter Knight Posted June 11, 2015 Share Posted June 11, 2015 Hello LostKobrakai, I have another question. Will you please tell me how can i add a contact from in my website? There's plenty of great form tutorials on the web if you'd like to try building your own PHP form. Make sure you also look at the Form module which Ryan built and makes it real sime to create forms, collect results and notify recipients etc https://processwire.com/talk/store/product/2-form-builder-single/ Link to comment Share on other sites More sharing options...
Martijn Geerts Posted June 11, 2015 Share Posted June 11, 2015 The problem has been sorted out. Thanks for your help. To catch up with a new question, without telling us and what went wrong doesn't feel right to me... probably it's just me.... 1 Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 11, 2015 Author Share Posted June 11, 2015 Hello Martijn Geerts, I am very new to this forum. Just joined yesterday. If it is wrong to ask another question under a previous topic then i extremely sorry. I will post that question again as a new topic. Thanks. 3 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted June 11, 2015 Share Posted June 11, 2015 Hi Citytech Tester, Please don't get me wrong, but I'm curious what went wrong. And probably others can learn from it to. And yes, you're free to ask more questions, preferable as you said in a new topic. You're welcome ! 1 Link to comment Share on other sites More sharing options...
Citytech Tester Posted June 12, 2015 Author Share Posted June 12, 2015 (edited) Hello Martijn Geerts, I just change the text format option in details section of the field that i added and in template i wrote <?php foreach($page->banners as $image) { $thumbnail = $image->size(350,200); echo "<a href='{$image->url}' title='{$thumbnail->description}'><img src='{$thumbnail->url}' alt='{$thumbnail->description}' ></a>"; } ?> it started working. Thanks Edited June 12, 2015 by LostKobrakai Please use the code block in the future. 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted June 12, 2015 Share Posted June 12, 2015 Looking great ! Thanks coming back on this! 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