The last few weeks I’ve been playing with EE to get the hang of it. One of the things that I noticed that I didn’t like was copying html tags across different templates. I realize that the easy way around this is to have a header and footer subtemplate that I include, but for a few reasons I wanted a different approach.
I came up with something using hidden templates and it seems a little unconventional. I’m getting ready to start heavy development and I don’t want to be painting myself into a corner with my approach. The main problem I see with the approach might be the overhead of including a few extra templates. I would appreciate any feedback.
first - I have an “inc” template group with two templates .index and .main_template ( I don’t use the index - its just a “no access” page - I probably could use index instead of .index - this is just the way I did it.)
inc/.index looks like:
<?
global $IN;
if (isset($IN->SEGS[1])&&$IN->SEGS[1]) {
$seg1 = $IN->SEGS[1];
$seg2 = (isset($IN->SEGS[2])&&$IN->SEGS[2]) ? $IN->SEGS[2] : 'index';
} else {
$seg1 = 'site';
$seg2 = 'index';
}
$template = $seg1.'/.'.$seg2;
echo '{embed="inc/.main_template" my_template ="'.$template.'"}';
?>Basically this is a “router” to send stuff where I want - this is a very rough first draft. A next addition is allow me to have simple url redirection like url=”/about_us.html” would display the entry url_title=“about_us” in a static_content blog. I know there is a pages modules - but it’s not working the way I wanted - this gives me full control.
next is inc/.main_template
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<title>my title.. needs work</title>
<meta http-equiv="Content-Type" content="text/html; charset={charset}" />
<link rel="stylesheet" href="/css/my.css" media="screen" />
[removed][removed] <!-- required -->
</head>
<body>
<div id="mycoolheader">Mysite</div>
<div id="mainbody">
<!-- the magic -->
{embed="{embed:my_template}"}
</div>
</body>
</html>
Then I create my normal template groups - eg site.
site/index is
{embed="inc/.index"}and I have a inc/.index
<div>this is the home page</div>
{embed="inc/.search_box"}and an inc/.other
here is some other contentand now if I access mysite.com/site/index - I get my “home page” or if I go to /site/other
I get the page with the other content.
That’s it.
The nice thing is that it lets me make new templates with no effort and have them all look the same. With a little tweaking, the “router” (inc/.index) could be made to allow you to choose other layouts besides .main_template
Does this seems like a good or bad idea?