public function view($slug = null)
    {
        //Checks if there exists a static page
        $static = StaticPage::get($slug);

        if ($static) {
            $page = new Entity(array_merge([
                'category' => new Entity(['slug' => null, 'title' => null]),
                'title' => StaticPage::title($slug),
                'subtitle' => null,
            ], compact('slug')));

            $this->set(compact('page'));

            return $this->render($static);
        }

        $slug = rtrim($slug, '/');
        $page = $this->Pages->findActiveBySlug($slug)
            ->contain([$this->Pages->Categories->getAlias() => ['fields' => ['title', 'slug']]])
            ->cache(sprintf('view_%s', md5($slug)), $this->Pages->getCacheName())
            ->firstOrFail();

        $this->set(compact('page'));
    }