Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

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

Closed
drewrawitz opened this issue Nov 7, 2017 · 4 comments
Closed

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

drewrawitz opened this issue Nov 7, 2017 · 4 comments
Labels

Comments

@drewrawitz
Copy link

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.

@drewrawitz
Copy link
Author

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?

@jedrzejchalubek
Copy link
Collaborator

jedrzejchalubek commented Nov 8, 2017

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.

@drewrawitz
Copy link
Author

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!

@drewrawitz
Copy link
Author

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants