Only Storyblok components that can ‘act as a content type’ may be used as Pages and are transformed into a matching Page class. They are similar to blocks but have some special features of their own.
All pages will use the DefaultPage class by default but you can specify your own types by simply making a class called ‘ComponentName’ within ‘app/Storyblok/Pages’ that extends Riclep\Storyblok\Page. For example a component called ‘kittens’ would become App\Storyblok\Pages\Kittens.
<?php
namespace App\Storyblok\Pages;
use Riclep\Storyblok\Page;
class Kittens extends Page
{
}Rendering pages
Every page implements a render() method that returns a view with the following data passed to it:
| Variable | Content |
|---|---|
title |
String for the page’s title |
meta_description |
String for the page’s meta description |
content |
Nested Blocks representing the page’s content |
seo |
Array of content from the Storyblok SEO app if used |
You are free to choose how you wish to display this data. You may want to create one single Blade file and loop over the nested objects. Alternatively you might pass some of the content to @includes. Each Block is also self-renderable - calling it’s render() method will pass it’s contents to a matching view.
Page title
Every page should have a <title> tag, to make populating that easy the Page class comes with a title() method. By default, if you have the Storyblok SEO app installed, it will use the SEO title, failing that it uses the name you gave when creating the page. If you want more control just override the method.
Meta description
If the Storyblok SEO app is installed this will return the description inputted there, if not installed it uses the value specified in the storyblok.php config file. Of course you can replace this method with your own logic.
Open Graph and Search Engine Optimisation
Storyblok comes with a handy plugin for managing your SEO and Open Graph meta data which we support out of the box. If you’re not using it, don’t worry, nothing will break.
By default Storyblok includes the SEO data within the page component’s content properties. We yank it out of there and put it in a seo property of the Page class separating the page’s meta and regular content, this is then passed to the view and can be used as so:
<!doctype html>
<html lang="en">
<head>
...
<meta property="og:title" content="{{ $seo['og_title'] }}">
<meta property="og:image" content="{{ $seo['og_image'] }}">
...
</head>
<body>
...
</body>
</html>