Multi site Onepager

Hello,

I got a onepager which has for example a page called “SEO Agentur Köln” and subpages for this. Now when I duplicate this page and call it “SEO Agentur Aachen” it should show me the content for Aachen there, but it doesn’t work. I get both pages shown in one site, which shouldn’t me the case.

Anyone knows how to do it?

My default.php looks like the following:

<?php
snippet('documentstart');

foreach($pages->visible() as $section) {
  foreach($section->children()->visible() as $content) {
    snippet($content->uid(), array('data' => $content));
  }
}

snippet('documentend');
?>

You are using $pages->visible(), which returns all visible pages on the top level of the site. To use the children of the current page instead, use $page->children()->visible().

And remove the first foreach loop …

@lukasbestle @texnixe That’s what I had before and I had the same issue as mentioned above.

Example development website:
http://diewebag.click/seo-agentur-koeln

This should only display the content of this page, but it actually doesn’t. It even doesn’t load the snippet for the footer anymore.

My structure:

If it doesn’t load the footer, you have an error on your page. Pls. turn on debugging in your config.php

c::set('debug', true);

Did:
<b>Fatal error</b>: Cannot redeclare class KUNDENTESTS\SealOfApproval in <b>/var/www/vhosts/diewebag.click/diewebag/site/snippets/kundentests.php</b> on line <b>13</b><br />

This is due to the fact, that Kirby loads the snippets two times in one page, which shouldn’t be happening. Each page should be having it’s individual onepager.

Could you pls. post the code of that snippet?

Edit: If you use this code in your template, I don’t see how it could possibly load all snippets twice:

foreach($page->children()->visible() as $content) {
    snippet($content->uid(), array('data' => $content));
  }

Sure, but I know that this won’t do the trick. Actually if you look at the generated HTML you can see that Kirby start appending content from the page for Aachen.

<?php
/**
 *  ElementSystems
 *  mail@elementsystems.de
 *  www.elementsystems.de
 *
 */
?>
<?php
    namespace KUNDENTESTS;
    header('Content-Type: text/html; charset=UTF-8');

    class SealOfApproval {
        private $params;
        private $fetchedData;
        private $endpointURI;

        public function __construct($params) {
            $this->endpointURI = 'https://endpoint.kundentests.com/endpoint.php';
            $this->params = $params;
            $this->fetchDataViaCurl();
        }

        public function getCompleteCode() {
            return $this->fetchedData->completeCode;
        }


        private function createUrlParams() {
            $encoded = '';
            foreach($this->params as $name => $value) {
              if(is_array($value)) {
                  foreach($value AS $arrayVal) {
                    $encoded .= urlencode($name).'='.urlencode($arrayVal).'&';
                  }
              } else {
                    $encoded .= urlencode($name).'='.urlencode($value).'&';
              }
            }

            $encoded = substr($encoded, 0, strlen($encoded)-1);

            return '?'.$encoded;
        }

        private function fetchDataViaCurl() {
            $ch = curl_init();
            curl_setopt($ch,\CURLOPT_URL,$this->endpointURI.$this->createUrlParams($this->params));
            curl_setopt($ch,\CURLOPT_RETURNTRANSFER,true);
            $output = curl_exec($ch);

            curl_close($ch);

            $jsonDecodedResult = json_decode($output);

            $this->fetchedData = $jsonDecodedResult;
        }
    }

    $params = array (
        'id'                => 22616,                            // int, required
        'width'             => 175,                             // int, optional
        'showReviews'       => false,                            // bool, optional
        'reviewsLimit'      => 5,                               // int, optional
        'reviewsType'       => 'top',                          // string, optional     last|top
        'socialMedia[]'     => [],     // array, optional
        'position'          => 'inline',                        // string, optional     inline|left|right
        'designFormat'      => 'portrait',                      // string, optional     portrait|landscape|small
        'designType'        => 'flat',                       // string, optional     default|flat
        'animatedDirection' => 'none',                          // string, optional     none|left|right
        'prefix'            => 'TOP TOP TOP'                               // string, optional     can only be used with "getCompleteCode()"
    );

    $SealOfApprovalObj = new SealOfApproval($params);
    echo $SealOfApprovalObj->getCompleteCode();
?>

Why do you define a class inside a snippet? Shouldn’t that be defined inside a plugin? Plugins are only ever loaded once.

Just started with Kirby, don’t know much. This thing is an external script though, but thanks for the tip, I may actually check that out.

This thread can be marked as solved. I made a mistake there. Had to define, as you already said, $page instead of $pages. Forgot to change that.

Thanks for your kind help. :slight_smile: