Jump to content

Is this template idea sensible?


Joss
 Share

Recommended Posts

Hi

Obviously, I am still only a couple of weeks or so into ProcessWire, so still at the foothills of my learning.

I needed to come up with a system so that if I want to radically change the construction of my site, I can without having to break into too many files.

They way I am working works, but is it a sensible way to proceed?

#########

Create three main files - header.inc, main_layout.inc, footer.inc and store them in a subdirectory - lets call in "includes"

These contain the main construction for the site.

Introduce some variables that will do the job of including specific markup for a specific template variation.

For instance put this in your main_layout.php somewhere in the markup:

<?php include("./includes/" . $maincontent); ?>

Create a file in your subdirectory that will have the markup (including fields) for some particular content. Lets call it my_template.inc.

Create a specific template file as normal in the main template directory - for instance, my_template.php. Add the following content to the file:

<?php

$maincontent = "my_template.inc";

include("./includes/header.inc");
include("./includes/main_layout.inc");
include("./includes/footer.inc");

?>

When this template is called, it will construct the template, adding the content from "my_template.inc" where the variable $maincontent is called.

This has now simplified the template process. If you want to change the layout of the site entirely, you only need to follow the same basic rules and edit the three main files.

#########

Obviously, this is pretty basic. In my working example I have three variables rather than just the one, but the principle holds. What I am trying to do is keep it all as simple as possible without introducing a lot of php that a) I don't understand properly ( :) ) and b) I will have trouble following in a years time when I want to change things round!

Interested in any opinions

Joss

Link to comment
Share on other sites

Morning Soma

Yes, I read through that just after I posted, though I need to look at a processwire installation to understand it properly. I hadn't noticed you can create a template without a file!

I notice that my system is possibly a little closer to Ryan's (well, sort of, but without all his clever bits), The main difference is that I split header, footer and the bit in the middle. The only reason I have done that is that in the site I am doing, I need to vary the header and footer for some parts of the sites, so I already had them split up.

The good thing about PW is there are so many ways to skin a cat.

It is less clear, however, which is the BEST way to skin it!!

Joss

Link to comment
Share on other sites

Morning Soma

Yes, I read through that just after I posted, though I need to look at a processwire installation to understand it properly. I hadn't noticed you can create a template without a file!

Well you can create a template without a file, but my approach is to use the aternative template field and use "main" for all templates, as this allows me to have one main template with all the main markup, and just the content part is being included via a template file that has the name of the template in PW. This allows to put all templates in a subfolder.

The good thing about PW is there are so many ways to skin a cat.

It is less clear, however, which is the BEST way to skin it!!

Joss

That's true, however I don't believe there's a BEST way. It has to be BEST way for you.

Link to comment
Share on other sites

It's simpler than you might think, maybe I can convince you to have another look at it by explaining the basics ;)

To make it very short. you have two important includes, main.php and blog.php. in main.php there is all the structural html that builds the page, in blog.inc you have the functions that will create most of the dynamic content. In almost all templates, both will be included, being main.php always the last thing in the file. This means that the variables that appear in the main.php code will get their content from blog.inc and from anything that comes in the middle of them. Here's a simple example focusing on the $headline variable:

in basic-page.php we have: (this is actually all there is in the file)

<?php

/**
* Basic Page template
*
*/

include_once("./blog.inc");
$headline = $page->get('headline|title');
include("./main.inc"); 

in main.inc we have:

if($headline) echo "<h2>$headline</h2>";

and in blog.inc we have:

$headline = '';

In blog.inc, $headline appears also as a parameter in some functions that will be later used in main.inc, but for making the point this is enough.

So, in the case of a basic-page we will have a heading with either the headline field content, or the page title;

On a template that doesn't define a headline variable between including blog.inc and main.inc, we wouldn't even have the <h2> tags printed (case of home.php);

And on the search page we have the result of this:

$headline = sprintf(__('You searched for: %s'), $query);

that will print "You searched for: whatever"

Link to comment
Share on other sites

hehe

Thanks Diogo

I will go through it properly at some point soon - I have a lot of other stuff to learn too, like some basic php! I have bookmarked this post, however, to help me.

The problem is that I am not a developer king, I am a cut and paste jester, which means I somehow manage to get things working, but more by luck than judgement.

I spend a lot of time being surprised when things actually work!

I get there eventually... sometimes!

Joss

  • Like 1
Link to comment
Share on other sites

Really? I sometimes need one of those ....

Edit: Well, at least it is related. In real life I was a sound engineer and dubbing mixer for 25 years (with lots of copywriting and padvertisign thrown in) and been a composer for the last 10 - I do things like this:

https://www.youtube.com/watch?v=ISaXZ5j6gv8&list=PLF9DEA78045F0988C&index=6&feature=plcp

But I don't get a lot of call for commissioned music on websites. Pity, audio is really rubbish on the internet - very underused.

  • Like 4
Link to comment
Share on other sites

The problem is that I am not a developer king, I am a cut and paste jester.

You used to be drunk when you drank 2 pints. Now you can handle 10 of those. The great thing about ProcessWire with some help from the likes of diogo and others and some logical thinking, a bit of exploring and some confidence you'll get there!

Link to comment
Share on other sites

I had a birthday this week ... I am now a bit further into my second half century. I probably ought to speed up a little ..... hah!

Oh, and I had to give up drinking (more or less) because of the first half century. I am sure there is something deeply philosophical in there somewhere.

Now, I must get back to my new PW site. I have just found a right old headache between how PW likes to be organised and how Bootstrap menus work. Typical.

  • Like 1
Link to comment
Share on other sites

Yes, I had already looked at that and decided going out and getting drunk was the next move.

Once I feel more secure with the system, I will creep up behind it and have another go ..... :rolleyes:

I feel the same way Joss.

After I downloaded and tried ProcessWire, I later found the Blog Profile, installed that into a new setup. While I really like how well it's designed (html and css wise). I couldn't grasp HOW things were getting pulled together into the page output.

Diogo explained it simply, and I think I may have to give it another go soon.

Link to comment
Share on other sites

  • 1 year later...

Well, I hate to give people indigestion over breakfast! 

:)

I normally use proper singers (or rather, singers who did not wreck their voices smoking, like I did), but I do occasionally like to give myself an outing other than backing vocals.

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...