Pagetitle and Meta Description for posts page | PyroCMS

The easiest way to define your own pagetitle and meta description for the posts page (the index view) is to simply set them directly like so:

// In your twig view
template.set('meta_title', 'Your page title')
template.set('meta_description', 'Your page description')
// And obviously you could do the same but with translations
template.set('meta_title', trans(..) )
template.set('meta_description', trans(...) )

Another way is to add a variables group, in this example we name it blog. We need to create two field, i normally use text-field and textarea-field allowing me to define max, min and recommended length. To follow along this example, make sure your slugs are named pagetitle and description.

Go to groups, and assign these fields to your blog. You are now able to edit the pagetitle and description by going to variables->manage blog. I'm now going to extend the default PostController:

namespace Pixney\WilliamastromTheme;
use Anomaly\VariablesModule\Variable\Command\GetVariableValue;
use Anomaly\PostsModule\Http\Controller\PostsController;
use Anomaly\VariablesModule\Variable\Contract\VariableRepositoryInterface;
/** * Class PixneyPostsController * * @link * @author Pixney. ( * @author William Åström ( */
class PixneyPostsController extends PostsController
{ public function index() { $this->template->set('meta_title',$this->setPageTitle()); $this->template->set('meta_description',$this->setDescription()); return $this->view->make('anomaly.module.posts::posts/index'); } private function setPageTitle() { return $this->dispatch(new GetVariableValue('blog', 'pagetitle', '')); } private function setDescription() { return $this->dispatch(new GetVariableValue('blog', 'description', '')); }

We will have to make sure this controller is used when displaying the blog post. We do this by creating a routes.php file the same way as we did here, and adding the following:

Route::get('blog',[ 'as' => 'anomaly.module.posts::posts.index', 'uses' => 'Pixney\WilliamastromTheme\PixneyPostsController@index',