tonik / theme

Tonik is a WordPress Starter Theme which aims to modernize, organize and enhance some aspects of WordPress theme development.

Home Page:http://labs.tonik.pl/theme/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proper way to assign a custom template to a page in the CMS?

drewrawitz opened this issue · comments

By default, there is no "Template" drop-down in the Page Attributes section when editing a page in the admin.

If I wanted to create a new template, let's say Homepage Template, what's the proper way to do that in Tonik?

I can create my template in the root of the theme that contains:

<?php
    /* Template Name: Homepage */
?>

but I feel like that's going against the whole templating system that Tonik uses. Is there another approach that I should be thinking about?

Thanks.

Would I do something like this:

<?php
/* Template Name: Homepage */

namespace App\Theme;

use function App\Theme\template;

template('homepage');

and then create a file templates/homepage.tpl.php and put all of my custom code in there?

Would I do something like this:

<?php 
/* Template Name: Homepage */

namespace App\Theme;

use function App\Theme\template;

template('homepage');

and then create a file templates/homepage.tpl.php and put all of my custom code in there?

This is exactly what I would do.

I like to think about root files as some way of "controllers". They receive data and delegate to templates. In most simple websites they probably will only contain a call to the template() function, but it really helps with separation of DB logic from layout layer and make it easy to re-use templates.

PS. It's maybe only an example, but for a homepage, I would switch WordPress reading settings to "static" and go with front-page.php and index.php files instead of creating a special template file.

Got it, makes sense!

Yeah, the only reason I like to create a special template file for the homepage is because I usually have a lot of ACF field groups that are specific to the homepage design. So I normally create a page in the admin called "Home" and assign it to the homepage template so I can manage all of the custom fields from that page and feed it through the template.

I suppose I could store the homepage settings in an ACF Options page and just use front-page.php but I like to keep it as a page to avoid any confusion.

Thanks for your help!

Although I just realized I can still assign ACF field groups to the "Front Page" page.

screen shot 2017-11-08 at 10 48 14 am

So you're right, there's no need to create a special template. Thanks!