Jump to content

How to display newly added field value in page.


Citytech Tester
 Share

Recommended Posts

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

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

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

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

$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

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.
Link to comment
Share on other sites

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

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