How Do You Include Multiple Page Content In One Php Include File?
Solution 1:
It sounds like you are trying to avoid templates. The basic idea is to define a separate file for each of head, footer, nav and include those from your content template.
head.php
<!doctype html> <html> ...
nav.php
<body> <a href=..> page1 </a> <a href=..> page2 </a> <a href=..> page3 </a>
foot.php
</body> </html>
And to create a complete page, you would do:
<?php
include 'head.php';
include 'nav.php'
An article about prune juice.
include 'foot.php';
?>
Now, if I understand correctly, you want to include only one file and be able to generate the various elements (head, nav, whathaveyou). You could do this by wrapping the include statements in functions:
ubertemplate
<?php
function head() { include 'head.php'; }
function nav() { include 'nav.php'; }
function randomElement() { ?>
An article about prune juice. <?php
}
function totalymisguideddynamiccontents() {
echo "<div> foobar <span> moo </span></div>"
}
function() { include 'foot.php'; }
?>
..then in your final page, call these functions:
uberpage
<?php
include 'ubertemplate.php';
?>
<?php head() ?>
<script src=superlib.js></src>
<?php nav() ?>
Yomama so big when she wears a yellow coat people yell TAXI!.
<?php foot() ?>
Finally, if I understand correctly and you think the uberpage approach seems like a good idea, ...then you should probably try it out. That may well be the only way to realize that it is flawed. I don't mean to mock your idea, but there are better ways to approach templates and the first way, the one you are trying to avoid, is cleaner (but that's only my opinion).
For a better way, look at twig templates or do some more research and find a framework that suits your needs.
Post a Comment for "How Do You Include Multiple Page Content In One Php Include File?"