Jump to content

Output all Fields of a Page/Template in a foreach and also output the value of the field


Orkun
 Share

Recommended Posts

Lets say i have a template with the following fields:

title

address_street

address_additional_road

address_zip_code

address_place

address_country

address_email

address_tel_1

address_tel_2

I want to output a table with the label of the field and the value of it.

$out .= "<h3>{$page->parent->title} Details</h3>
             <div class='span8'>
                <table class='detail-view table table-striped table-condensed'>";
                
                 $out .= "<tr class='odd'><th>ID</th><td>{$page->id}</td></tr>";

                 //get all the fields:
                 $all_fields = $page->fields;

                 foreach($all_fields as $field){
              
                   $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field)}</td></tr>";

                 }
                 $out .= "<tr class='even'><th>erstellt von</th><td>{$page->createdUser->name}</td></tr>
                          <tr class='odd'><th>erstellt</th><td>".date("Y-m-d H:i:s", $page->created)."</td></tr>
                          <tr class='even'><th>aktualisiert</th><td>".date("Y-m-d H:i:s", $page->modified)."</td></tr>";
                

$out .= "       </table>
            </div>";

In the foreach, it only outputs the title and I also get warnings:

Warning: Illegal offset type in /Users/praktikant/Sites/Kulturdatenbank.pw.2.0/wire/core/WireData.php on line 41

Warning: Illegal offset type in isset or empty in /Users/praktikant/Sites/Kulturdatenbank.pw.2.0/wire/core/WireData.php on line 39

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

×
×
  • Create New...