webhoes Posted August 5, 2017 Share Posted August 5, 2017 I want to make flexible onepager website. The tree as follows: Home (seperate first page not to be in the onepager) Page 1 (template 1) Child 1 (template 2) Child 2 (template 3) Child 3 (template 2) Child 4 (template 4) The children need to be outputted in the order as in the admin. The templates (2,3,4) just contain the code for that particular section. All the main layout is in _main.php. I tried several foreach loops but none work. This an example of my last try... <?php foreach ($page->children as $c){ $out .= wire('pages')->get($c->id)->render; } echo $out; ?> I just can't output just the content of the template of the child pages within the parent page (Page 1). Can anyone give me some input towards a solution... Link to comment Share on other sites More sharing options...
maxf5 Posted August 5, 2017 Share Posted August 5, 2017 Wont something like this work for you? <?php $sections = $pages->get("/page1")->children; foreach ($sections as $s) { $type = $s->template; switch ($type) { case "template2": $out .= "<h2>{$s->title}</h2>"; $out .= "<p>{$s->text}</p>"; break; case "template3": $out .= "<h2>{$s->title}</h2>"; $out .= "<img src='{$s->img}'>"; break; } } echo $out; ?> Link to comment Share on other sites More sharing options...
webhoes Posted August 5, 2017 Author Share Posted August 5, 2017 I was already working on something like that... _func.php function renderChildPages($items){ $out = ''; foreach ($items as $item){ $i = $item->template->get("name"); switch ($i) { case "diensten": $out .= renderDiensten($item->id); break; case "activiteiten": $out .= renderActiviteiten($item->id); break; case "over": $out .= renderOver($item->id); break; default: //; } } return $out; } function renderDiensten($page){ $output = ''; $output = ' <section id="services"> <div class="container"> <div class="heading wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms"> <div class="row"> <div class="text-center col-sm-8 col-sm-offset-2"> <h2>' . $page->title . '</h2> <p>' . $page->body . '</p> Test </div> </div> </div> <div class="text-center our-services"> <div class="row"> '; foreach ($page->repeater as $r) { $out .= '<div class="col-sm-4 wow fadeInDown" data - wow - duration = "1000ms" data - wow - delay = "300ms" > <div class="service-icon" > <i class="fa fa-flask" ></i > </div > <div class="service-info" > <h3 >' . $r->title . '</h3 > <p >' . $r->body . '</p > </div > </div >'; } $output .= $out; $output .= '</div> </div> </div> </section><!--/#services-->'; Return $output; } Template <?php echo renderChildPages($page->children); ?> </div> The childpages on themselves work fine, but getting their values in the foreach is not working yet... Link to comment Share on other sites More sharing options...
webhoes Posted August 5, 2017 Author Share Posted August 5, 2017 Aha... loosing ->id does the trick. 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