As I normally hand-author my sites without any aid of templating, SSG, or CMS; take my advice with a grain of salt...
other way to create a templating/shared code system... besides php include? but you obv need to use .php files for every page if you want to do that, so is there any kind of alternatives
If you only want to include header code and footer code, there is also
Server-Side Includes (SSI: those files with `.shtml` extension and weird-looking HTML comments) This stuff is done by the server itself; and is being a another primitive server-side technology which has been around since forever.
And also having nested layouts too, like layout default referencing layout barebones.
Yes, SSI does support nested include: by including other SHTML file. (Or even output from other CGI or PHP programs, which have their own include mechanism)
Just be aware that while parameter-passing between the including file and included file exist in SSI-- it does have limit. The variable you set on the main file would appear in the included subfiles, but you cannot call a subfile by using current file content as parameter. Thus your template in this scheme would have to be structured in
sandwich-like fashion
(1):
- Header template content (included by main file)
- Actual content (right in the main file)
- Footer template content (included by main file)
When there are parent template and child template, an overall sandwich structure would be a bit more complicated like:
- Child header template (included by main file)
- Parent header content (included by child header template)
- Child header content (inside child header template)
- Actual content (right in the main file)
- Child footer template (included by main file)
- Child footer content (inside child header template)
- Parent footer content (included by child footer template)
^ But in the actual main file, you only have to include the child header+footer template; and not the parent ones.
Since you're basically trying to find alternative to PHP `include()`; this SSI include operates within pretty much the same sandwich scheme and the same set of limitations as PHP include, so that should be no problem.
For a full reference documentation of SSI function in Apache WWW server, see its
mod_include manual (which is more nerdy about this than the quick-start tutorial I linked above). Make sure to check that your server is Apache before you try though.
(1) As opposed to hotdog-like fashion (template that wraps over the content) commonly used in SSG templating scheme.