Skip to navigation

How To Set A Custom Template For Single Pages In Concrete 5.7

Written by and published on

When you create a single page in Concrete5, it uses the view.php template by default. Another option is to create a template file with the same name as the single page, in which case that template is used instead.

Neither of these options is great if you have multiple single pages that require the same template. Luckily, the solution is very simple.

1. Create the template you want to use and register it via the dashboard, for example my_custom_template.php

<div class="my-content-wrapper">
<?php echo $innerContent; ?>
</div>

2. In the page controller for the single page, add the $themeViewTemplate attribute:

<?php
namespace Application\Controller\SinglePage;

use PageController;

class MyCustomPage extends PageController {
  protected $themeViewTemplate = 'my_custom_template';

  // Rest of the stuff...

After this the single page will use my_custom_template as the template.

Note The mime type will always be text/html by default. If you want to create a template for, let’s say, XML content, you need to do some additional work.

Comments

Commenting has been disabled until I get a proper spam protection working. =(

External Links

Back to beginning