Jump to content

[SOLVED] How do i get first field of repeat field and outpit into site ?


picarica
 Share

Recommended Posts

so i am trying to fetch repeat field from page and output it, but only first one !, i thought first() would work and i googled something and came up with this

                        if ($pages->get('/ponuka/')->title) {
                            $ponuka = $pages->get('/ponuka/');
                        } else {
                            $ponuka = $pages->get(1239);
                        }
                        //echo $ponuka;
                        foreach($ponuka->children as $child) {
                            $first = $child->repeat_body->find("limit=1");
                            $image = $child->pod_thumb;
                            $options = array('quality' => 70, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium');
                            $thumb = $image->size(400, 300, $options);
                            echo "
                        <li>
                            <h3>$child->title</h3>
                            <div class='split reversed'>
                                <div class='content'>";
                                foreach($ponuka->repeat_body->find("limit=1") as $rep) {
                                    echo $rep->body;
                                }
                                    echo "<ul class='actions'>
                                        <li><a href='{$child->repeat_body->first()->url}' class='button'>Pokračovať</a></li>
                                    </ul>
                                </div>
                                <div class='image'><img src='$thumb->url' alt='' /></div>
                            </div>
                        </li>";
                        }

first check is just, if client somehow renames the site or changes url of that site, that it would fall back to fetching it from ID, and if they delete that site and create new one but with same name it will still work, so i hope that wont be a problem, then i output some stuff from that site, but i have trouble outputting the repeat field, as you can i see i tried it with find but didnt worked, what is the correct way to approach this ?

Link to comment
Share on other sites

According to the docs repeaters are just PageArrays, so both first() (method) and first (property) should work.

Looking at your code very hastily, I think you’re looking for this:

echo $child->repeat_body->first->body;

Does this line not work already?

<li><a href='{$child->repeat_body->first()->url}' class='button'>Pokračovať</a></li>

 

Link to comment
Share on other sites

14 hours ago, Jan Romero said:

According to the docs repeaters are just PageArrays, so both first() (method) and first (property) should work.

Looking at your code very hastily, I think you’re looking for this:


echo $child->repeat_body->first->body;

Does this line not work already?


<li><a href='{$child->repeat_body->first()->url}' class='button'>Pokračovať</a></li>

 

ye that link just links to my-url.com/processwire/repeaters/for-field-158/for-page-1240/1604946038-3619-1/

so i guess it works? or odesnt not sure.

EDIT: okey it works like that

                                    echo $child->repeat_body->first()->body;

i dont know what happend probably mistyped, okay it works thanks !

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.
  • Similar Content

    • By SwimToWin
      Hi, I am in the process of creating a local news site, based on ProcessWire.
      Among other things, the site will be presenting local events, and I have a question specifically about recurring events.
      Events (recurring or not) shall be shown in *one* list, like in this example:
      10.01.2019 19:30 - Some event (Page #1235) 11.01.2019 17:15 - Another event (Page #1237) 12.01.2019 16:00 - The Final Event (Page #1239) When I have recurring events, I would like to keep these on the same page (using a Repeater field) as shown here:
      10.01.2019 19:00 - A Star is Born film, showing in Cinema ABC (Page #1234 holds all occurrences) 10.01.2019 19:30 - Some event (Page #1235) 11.01.2019 19:30 - A Star is Born film, showing in Cinema ABC (Page #1234 holds all occurrences) 11.01.2019 17:15 - Another event (Page #1237) 12.01.2019 20:00 - A Star is Born film, showing in Cinema ABC (Page #1234 holds all occurrences) 12.01.2019 16:00 - The Final Event (Page #1239) The editing interface will use these fields:
      id title date_start - a datetime field (use for one-time events) time_start - a text field dates - Repeat field with these sub-fields: date_start - a datetime field (use for recurring events) time_start - a text field Listing events by date_start is simple when the site only has run-once events (using the 'date_start' field). But when repeated events enter the picture, it is necesssary to generate all occurrences for each repeated event ('dates.date_start') - and join these with the list of run-once events ('date_start'). I am unsure if that is possible?
      PS: I am aware that Ryan created an Events fieldtype module, unfortunately the site needs more detail about each event than this module offers so it is easier to create a site-specific set of Event fields.
×
×
  • Create New...