Jump to content

trouble with tag include


ladytf
 Share

Recommended Posts

HI,

 

i created a php pag, and i want that page are the base on all my pages (like a template). i did include and indicate that page but when i run the css associate to the base page doesn't appears.

 

Why???

 

I hope make me understand, i'm very bad in english.

Link to comment
Share on other sites

Could be many things based on your OP so please post the relevant part of your code.

Edited by niche
Link to comment
Share on other sites

page template.php

<!doctype html><html><head><meta charset="utf-8"><title>Template</title><link href="design.css" rel="stylesheet" type="text/css"></head><body><div class="wrapper"><header>	<div style="position: absolute; ">		<img src="img/garfield_cozinheiro001.gif" width="86" height="103" style="float: left; margin-left: 100px">	</div>Minhame Minhame</header><nav><ul>		<li><a href="#">Home</a></li>        <li><a href="#">Comer</a></li>        <li><a href="#">Beber</a></li>        <li><a href="#">Contacte-nos</a></li></ul></nav><div class="menu">	<h1>Conversor de unidades</h1>    <p></p>    	<center>		<select id="conversor" onchange="converter();" value="submit">        		 <option>--------</option>                 <option id="1">Volvo</option>                 <option id="2">Saab</option>                 <option id="3">Mercedes</option>                 <option id="4">Audi</option>		</select>                <div id="resultado"></div>                <script type="text/javascript">						function converter (){								if (option = document.getElementById("conversor").value=="Volvo"){				document.getElementById("resultado").innerHTML="Volvo <br> ola";				}				else if (option = document.getElementById("conversor").value=="Saab"){				document.getElementById("resultado").innerHTML="Saab";				}				else if (option = document.getElementById("conversor").value=="Mercedes"){				document.getElementById("resultado").innerHTML="Mercedes";				}				else if (option = document.getElementById("conversor").value=="Audi"){				document.getElementById("resultado").innerHTML="Audi";				}						}		        </script>        </center>	</div></div></body></html>

page index.php

<?php	include ('template/template.php');?><!doctype html><html><head><meta charset="utf-8"><title>Pagina Inicial</title></head><body></body></html>
Link to comment
Share on other sites

try this:

<!doctype html><html><head><meta charset="utf-8"><title>Pagina Inicial</title></head><body><?php	include ('template/template.php');?></body></html>

and delete everything in template.php above the body tag including the body tag.

 

EDIT:

 

include is not a tag it's a statement. you can drop the ().

 

http://www.w3schools.com/php/php_includes.asp

Edited by niche
Link to comment
Share on other sites

Then reverse it.

 

leave template.php per OP and make index.php: I don't think it's demanded that all the overhead above the the body tag, including the body tag, reside in the index. Obviously, you have it in the template. I do know it shouldn't be rendered twice.

<?php	include ('template/template.php');?>
Edited by niche
Link to comment
Share on other sites

That's not a template page, that is just inserting the whole page content into another page which you can't do, well you can, but its not valid.

template page you define areas that will show specific content, title, meta tags, main content etc, then you use a separate page, to gather information from database, or manually and assign to those specific areas on the template.

  • Like 1
Link to comment
Share on other sites

template.tpl (square brackets show where specific will be placed)

<!DOCTYPE HTML><html>    <head>        <title>[title]</title>        <meta charset="UTF-8" />        <link href="[basedir]images/favicon.ico" rel="icon" type="image/x-icon" />        <meta name="description" content="[metadescription]" />        <meta name="keywords" content="[metakeywords]" />        <meta name="author" content="john doe" />        <link rel="stylesheet" type="text/css" href="[basedir]css/template.css" />        <link rel="stylesheet" type="text/css" href="[basedir]css/menu.css" />        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>        <script type="text/javascript" src="[basedir]scripts/template.js"></script>        <script type="text/javascript">            document.createElement("article");            document.createElement("footer");            document.createElement("header");            document.createElement("hgroup");            document.createElement("nav");        </script>        <!--[if IE ]>        <link rel="stylesheet" type="text/css" href="[basedir]css/templateIE.css" />        <![endif]-->        <!--[if lt IE 7]>        <link rel="stylesheet" type="text/css" href="[basedir]css/templateIE6.css" />        <script type="text/javascript" src="[basedir]scripts/IE6.js"></script>        <![endif]-->    </head>    <body>        <div id="wrapper">            <header>                <!-- content goes here manually -->                <nav><!-- menu content is inserted here -->                    [menu]                </nav>            </header>            <section><article class="details_wrapper">[content]</article>            </section>            <footer>[footer]</footer>        </div>    </body></html>

functions.php contain function,classes to process and output content. the menu was done dynamically from DB to produce menu and submenus, i just added simply menu.

 

<?phpclass Template { public $basedir = "http://localhost/web_testing/Templates/"; public $output; public $file; public $values = array(); function __construct($file) { $this->file = $file; $this->output = file_get_contents($this->file); } function set($key, $value) { $this->values[$key] = $value; } function output() { foreach ($this->values as $key => $value) { $tagsToReplace = "[$key]"; $this->output = str_replace($tagsToReplace, $value, $this->output); } return $this->output; }}// output the menufunction getdefaultmenu($basedir) { $text_join = '<ul>'; $text_join.='<li><a href="' . $basedir . '">Home</a></li>'; $text_join.='<li><a href="' . $basedir . 'aboutus.php">About us</a></li>'; $text_join.='<li><a href="' . $basedir . 'contactus.php">Contact Us</a></li>'; $text_join.= '</ul>'; return $text_join;}// use to identify curent page and set menu link to this page as activefunction curPageURL() { $pageURL = 'http'; //if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; $pageURL = str_replace("&", "%26", $pageURL); } return $pageURL;}?>


index.php

<?phprequire("functions.php");$menucont = "";//Meta Title Length = 63 characters//Meta Keyword tag = 256 characters//Meta Description tag = 156 characters$metakeywords = 'metakeyword go here';$metadescription = 'website description here';$title = 'page title goes here';$content = '<h1>Welcome</h1><section id="intro"><p>blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p></section><section id="general_care">  <h2>Welcome Again<br />    <p>blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p></section><section><h3>Welcome once again</h3>    <p>blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p></section>';$TagContent = new Template('template.tpl');require_once("default_templ_content.php");echo $TagContent->output();?>

aboutus.php

<?phprequire("functions.php");$metakeywords = 'meta keywords about us';$metadescription = 'meta description about us';$title = "about us title";$content = '<h1>About us </h1><section id="intro"><p>about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah,  </p></section><section id="general_care">  <h2>About us  Again<br />    <p>about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah,  </p></section><section><h3>About us once again</h3>    <p>about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, about us blah blah, </p></section>';$TagContent = new Template('template.tpl');require_once("default_templ_content.php");echo $TagContent->output();
Edited by dsonesuk
  • Like 1
Link to comment
Share on other sites

  • 2 weeks 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

×
×
  • Create New...