Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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

Posted (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 by LostKobrakai
Edited the code box in. Please use these in the future.
Posted

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("/");
Posted

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?

Posted

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/

Posted

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

  • Like 1
Posted

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.

  • Like 3
Posted

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 !

  • Like 1
Posted (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 by LostKobrakai
Please use the code block in the future.
  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...