Jump to content

How to list content of fields?


justnew77
 Share

Recommended Posts

Hi,

my site have a page that I use as an container. Name CONTAINER.

CONATINER has children. Each of them has fields in it.

What I want ist this:

On an other page I want to list all the content of the fields from

CONTAINER children.

How can I do that?

In MODx there was a plungin called getResources to do that. How it is here?

Link to comment
Share on other sites

There was a bug in the code sorry.

Maybe it's better to explain what i've done.

// get the parent         // the children of the page under www.your-domain.com/container/
$pages->get('/CONTAINER/')->children <-- this is a page array
// now you can foreach this, because it is an array.
$children = $pages->get('/CONTAINER/')->children;

foreach($children as $p) {      
    $all_fields = $p->fields; // fields are all the fields in the template from this page. (array)

    foreach($all_fields as $f) { // every field $f
        echo $p->$f . "<br>"; // $p, the page in the `outerloop`, $f all fields in $p
    }

}
Link to comment
Share on other sites

To get content from a field of one children page that you know the name, do this;

echo $page->get("parent=$page, name=name-of-page")->field;
 

To get more fields do this:

$myPage = $page->get("parent=$page, name=name-of-page")->field;

echo $myPage->field1;

echo $myPage->field2;
 

To get the fields from all children do as Martijn pointed out. Basicly, you will be looping through all the children, and extract the fields from each one of them. An important thing to know is that get() get's one page and you can immediately retrieve the fields, while find() gets a group of pages and you only have access to their properties when you iterate them (with foreach() for instance.)

  • Like 1
Link to comment
Share on other sites

foreach($pages->get("/video-container/")->children as $p) {
    echo $p->folgeTitel . "<br>";
    echo $p->folgeYT . "<br>";
}
 

edit: Well, now you have two answers... find the differences ;)

  • Like 3
Link to comment
Share on other sites

Hi there,

I got a new field (an image field, only 1 images allowed)

The problem now is that the images can not display becauese the field contains only the filename and NOT the path.

 echo "<img src='{$item->folgePic}'>";

What can I do to recieve the full path and name?

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