I am having trouble with my php template system.
I have a file containing all my html that is repeated(header and layout etc). I include this file in all my html pages so I don't have to repeat all the code in every page.
***html file***
***file.php***Code:<?php $title = "Tango Monkeys"; ?> <?php include $_SERVER['DOCUMENT_ROOT'] . '/' . $dir . '/includes/file.php'; ?>
It works fine until I want to have different html tags in my variable.Code:<?php if(isset($title)) { echo $title; } else { echo "Death rabbit bear"; } ?>
Above works fine, but if I put any divs inside that variable I get a parse error.Code:<?php $title = " Tango Monkeys firedragon <h1>applesauce</h1> "; ?>
Obviously this is a problem because my html pages need html tags.
I am using variables in file.php, because if cannot use a function to get file contents because each webpage is in a different place and I only want a section of content from the current file anyway.
Before I was using multiple includes such as:
include $_SERVER['DOCUMENT_ROOT'] . '/' . $dir . '/includes/header1.php';
include $_SERVER['DOCUMENT_ROOT'] . '/' . $dir . '/includes/body1.php';
include $_SERVER['DOCUMENT_ROOT'] . '/' . $dir . '/includes/footer.php';
And then inserting my html content between body and footer.
This worked fine, but as you can see I am using multiple includes which scatters my repeated content accross different include files which is messy.
So I am working on having only 1 include file called upon by each webpage and in this include file, having variables for different content and in the webpage are the content for the variables.
I also notice that I have to declare the variables before I include the php file or it does not work. So I would have a list of html content assigned to php variables at the top, and then import the php file which has the page structure and calls upon the variables at the right places in the template(repeated) html content in that file.
As I said though, I am having trouble with assigning long html content with html tags in the variables.





Bookmarks