Split page.tpl.php into page.tpl.php and page_admin.tpl.php
| Project: | CivicSpace Theme |
| Version: | HEAD |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | traemccombs |
| Status: | closed |
Jump to:
I love the direction that the CivicSpace themes are going but the current page.tpl.php is becoming sort of like its own mini-application due to all of the logic inside of it. This patch splits it into page.tpl.php and page_admin.tpl.php. Before, the difference was always calculated in the template by calling civicspace_is_admin() and making an if/else branch. This leads to very hard-to-read templates. Now, civicspace_is_admin() is called only once, in the page hook of _phptemplate_variables (template.php), and it uses the nifty phptemplate.engine feature that you can specify the template file to use by setting a variable:
<?php
// Set admin theme
if (civicspace_is_admin()) {
$vars['template_file'] = 'page_admin';
}
?>Besides being more readable, there are performance benefits as well. The new page.tpl.php is 2.4 KB smaller and the new page_admin.tpl.php is 3.9 KB smaller than the old page.tpl.php, plus there are 7 fewer calls to civicspace_is_admin().
| Attachment | Size |
|---|---|
| cs_patch.txt | 16.18 KB |

#1
#2
+1
We've been planning a custom solution for this where each sub style can have it's own page.tpl.php system and choose to include what the author wants. In this case, the page_admin.tpl.php would make sence, but the code would need to be customized to be slightly more robust eg: using path_to_style and some checking to see if it's used or if it uses a custom tpl the style employs.
This code, however, is a great start on that, and will greatly simplify the process once it starts. Great stuff Robert!
Robin
#3
I like this too. Right now page.tpl.php is a mess, very hard to read and if you want to further customize either the regular pages or admin pages it requires more thought.
I have been looking into doing something similar too, as I want to have basically 2 faces to my websites... the public face and then then private face, which would also include admin functions. Basically you have your public corporate website and your private intranet, same website, but just 2 different users, with some clever page.tpl.php magic. Seems to me that CStheme is trying to do similar by spliting the admin section out so it can have a different layout (fluid instead of fixed is the biggest plus).
I'll try and look more at this code I'm very intrigued...
#4
The code is simple. The only addition I made I posted above, and you could extend this to any number of page_x.tpl.php files. I want to make a nice page_xml.tpl.php which would be what gets returned by AJAX calls, for example.
#5
This has been applied to CVS HEAD with minor changes.
Thanks Robert for you great patch and help!
Robin
#6
Thanks tons guys! Closing ticket.