picarica Posted November 9, 2020 Share Posted November 9, 2020 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 More sharing options...
Jan Romero Posted November 10, 2020 Share Posted November 10, 2020 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 More sharing options...
picarica Posted November 10, 2020 Author Share Posted November 10, 2020 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now