Jump to content

Include header and footer wont show content


Troost
 Share

Recommended Posts

Hiya,

Im working for the first time with PW. I tried to order my templates by including the head.inc and the footer.inc but those won't show content.

The CSS from the head.inc loads, and everything works, but the content from the fields wont show.

Can anyone help me out? Or does anyone know how to fix this?

I can't show it online at the moment, because I'm working on MAMP.

(Sorry for my english)

<?php 
include("./header.inc");?>

<div class="row main-content">
			<div class="nine columns">
				<?php echo $page->body; ?>
			</div>
			<div class="three columns">
				<?php echo $page->sidebar; ?>
			</div>
		</div> <!-- END MAINCONTENT -->

<?php 
include("./footer.inc"); ?>

Link to comment
Share on other sites

Hi Pjg, thanks!

This is the home.php

<?php 
include("./header.inc");?>

		<div class="row main-content">
			<div class="four columns">
				<?php echo $page->video; ?>
			</div>
			<div class="four columns">
				<?php echo $page->photo; ?>
			</div>
			<div class="four columns">
				<?php echo $page->results; ?>
			</div>
		</div> <!-- END MAINCONTENT -->

<?php 
include("./footer.inc"); ?>

This is the header.inc

<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if IE 9]>    <html class="no-js ie9" lang="en"> <![endif]-->
<!-- Consider adding an manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 9]><!--> 
<html class="no-js" lang="en" itemscope itemtype="http://schema.org/Product"> <!--<![endif]-->
<head>
	<meta charset="utf-8">

	<!-- Use the .htaccess and remove these lines to avoid edge case issues.
			 More info: h5bp.com/b/378 -->
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<title><?php echo $page->title; ?></title>

	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">

	<!-- We highly recommend you use SASS and write your custom styles in sass/_custom.scss.
		 However, there is a blank style.css in the css directory should you prefer -->
	<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/gumby.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/style.css" />

	<script src="<?php echo $config->urls->templates?>js/libs/modernizr-2.6.2.min.js" /></script>
</head>

<body>

	<div id="wrapper">
		<div class="row social">
			<div class="two columns socialmedia">			
				<?php echo $page->social_icons; ?>
			</div>
			</div>
		
		<div class="row top">
			<div class="three columns logo"><?php echo $page->logo; ?></div>
			<div class="nine columns navigation">
				<ul class="main-nav">
					<ul><?php
						foreach($page->children as $child)
						   echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
						?>

					</ul>
				</ul>
			</div> <!-- END NAVIGATION -->
		</div>

	<div class="row header">
				<div class="twelve columns header-image"><?php echo $page->header; ?></div>
			</div><!-- END HEADER -->
		</div><!-- END TOP -->
		<div class="clear"></div>

And this is the footer.inc

<div class="row footer">
			<div class="six columns footer-logo">
				<?php echo $page->sponsors; ?>
			</div>

			<div class="six columns footer-icons">
				<ul class="socialicons">
					<li class="social-icon-instagram"></li>
					<li class="social-icon-facebook"></li>
					<li class="social-icon-youtube"></li>
				</ul>
			</div> 

		</div> <!-- END FOOTER -->

	</div> <!-- END WRAPPER -->


	<!-- Grab Google CDN's jQuery, fall back to local if offline -->
	<!-- 2.0 for modern browsers, 1.10 for .oldie -->
	<script>
	var oldieCheck = Boolean(document.getElementsByTagName('html')[0].className.match(/\soldie\s/g));
	if(!oldieCheck) {
	document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"><\/script>');
	} else {
	document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"><\/script>');
	}
	</script>
	<script>
	if(!window.jQuery) {
	if(!oldieCheck) {
	  document.write('<script src="js/libs/jquery-2.0.2.min.js"><\/script>');
	} else {
	  document.write('<script src="js/libs/jquery-1.10.1.min.js"><\/script>');
	}
	}
	</script>

	<!--
	Include gumby.js followed by UI modules followed by gumby.init.js
	Or concatenate and minify into a single file -->
	<script gumby-touch="js/libs" src="js/libs/gumby.js"></script>
	<script src="js/libs/ui/gumby.retina.js"></script>
	<script src="js/libs/ui/gumby.fixed.js"></script>
	<script src="js/libs/ui/gumby.skiplink.js"></script>
	<script src="js/libs/ui/gumby.toggleswitch.js"></script>
	<script src="js/libs/ui/gumby.checkbox.js"></script>
	<script src="js/libs/ui/gumby.radiobtn.js"></script>
	<script src="js/libs/ui/gumby.tabs.js"></script>
	<script src="js/libs/ui/gumby.navbar.js"></script>
	<script src="js/libs/ui/jquery.validation.js"></script>
	<script src="js/libs/gumby.init.js"></script>

	<!--
	Google's recommended deferred loading of JS
	gumby.min.js contains gumby.js, all UI modules and gumby.init.js

	Note: If you opt to use this method of defered loading,
	ensure that any javascript essential to the initial
	display of the page is included separately in a normal
	script tag.

	<script type="text/javascript">
	function downloadJSAtOnload() {
	var element = document.createElement("script");
	element.src = "js/libs/gumby.min.js";
	document.body.appendChild(element);
	}
	if (window.addEventListener)
	window.addEventListener("load", downloadJSAtOnload, false);
	else if (window.attachEvent)
	window.attachEvent("onload", downloadJSAtOnload);
	else window.onload = downloadJSAtOnload;
	</script> -->

	<script src="js/plugins.js"></script>
	<script src="js/main.js"></script>

	<!-- Change UA-XXXXX-X to be your site's ID -->
	<!--<script>
	window._gaq = [['_setAccount','UAXXXXXXXX1'],['_trackPageview'],['_trackPageLoadTime']];
	Modernizr.load({
	  load: ('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js'
	});
	</script>-->

	<!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
	   chromium.org/developers/how-tos/chrome-frame-getting-started -->
	<!--[if lt IE 7 ]>
	<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
	<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
	<![endif]-->

  </body>
</html>

Link to comment
Share on other sites

This is the error.txt

2015-02-08 13:28:41	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '<' (line 5 of /Applications/MAMP/htdocs/pw/site/templates/home.php)
2015-02-08 13:29:05	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '<' (line 5 of /Applications/MAMP/htdocs/pw/site/templates/home.php)
2015-02-08 14:20:41	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' (line 34 of /Applications/MAMP/htdocs/pw/site/templates/header.php)
2015-02-08 14:26:16	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '.' (line 39 of /Applications/MAMP/htdocs/pw/site/templates/header.php)
2015-02-08 14:26:23	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '->' (T_OBJECT_OPERATOR) (line 39 of /Applications/MAMP/htdocs/pw/site/templates/header.php)
2015-02-08 14:26:24	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '->' (T_OBJECT_OPERATOR) (line 39 of /Applications/MAMP/htdocs/pw/site/templates/header.php)
2015-02-08 14:28:58	admin	http://localhost:8888/pw/	Error: 	Allowed memory size of 134217728 bytes exhausted (tried to allocate 62537728 bytes) (line 54 of /Applications/MAMP/htdocs/pw/site/templates/header.php)
2015-02-08 14:29:39	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '<' (line 3 of /Applications/MAMP/htdocs/pw/site/templates/home.php)
2015-02-08 14:29:39	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '<' (line 3 of /Applications/MAMP/htdocs/pw/site/templates/home.php)
2015-02-08 14:29:42	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '<' (line 3 of /Applications/MAMP/htdocs/pw/site/templates/home.php)
2015-02-08 14:56:02	admin	http://localhost:8888/pw/	Parse Error: 	syntax error, unexpected '<' (line 2 of /Applications/MAMP/htdocs/pw/site/templates/header.inc)
2015-02-08 14:56:58	admin	http://localhost:8888/pw/photos/	Parse Error: 	syntax error, unexpected ')' (line 43 of /Applications/MAMP/htdocs/pw/site/templates/header.inc)

Link to comment
Share on other sites

It seems like you've changed stuff around, so the error messages aren't really helpful. I can't be sure if the line the error comes from is still the line in your code above. But it looks like that there is html code where the parser is expecting php code. So maybe adding a "?>" in front of that line could help, while it normally shouldn't be necessary for included files.

Link to comment
Share on other sites

I'm a beginner at PHP5, but I wonder if naming the file(s) header.inc.php (footer.inc.php) or _header.php (_footer.php) wouldn't have resolved the problem.

And/or (just) adding this at the beginning (like in the site-classic profile for example) - with or without comments - (for the footer it may be different): 

<?php

/**
 * Demo site header include file (HTML5)
 *
 * Note that this file has nothing to do with ProcessWire. We just split our common
 * header and footer markup into separate files (head.inc and foot.inc) like this,
 * since it was common to all of our templates.
 *
 */

?>
Link to comment
Share on other sites

@Christophe:

Naming wouldn't have made a difference as the files you include can be called almost anything as long as the code contained within them is valid php. As a matter of fact one of my standard include files is called "onions" (without suffix etc) purely because it amuses me when I can resolve an incident with the explanation that "I have lost my onions"...

The latter suggestion merely provides context to human (and certain machine) readers, which in the final evaluation of the code is ignored by the server.

  • Like 1
Link to comment
Share on other sites

How does that solve what? This code doesn't do anything. The selector doesn't do anything. And I don't see $header being used anywhere.

I dont know how it happend, but it happend. A colleague of mine told me to place this at the top of the header.inc page

New header.inc

<?php
	$header=$pages->get('1012');
?>

<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if IE 9]>    <html class="no-js ie9" lang="en"> <![endif]-->
<!-- Consider adding an manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 9]><!--> 
<html class="no-js" lang="en" itemscope itemtype="http://schema.org/Product"> <!--<![endif]-->
<head>
	<meta charset="utf-8">

	<!-- Use the .htaccess and remove these lines to avoid edge case issues.
			 More info: h5bp.com/b/378 -->
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<title><?php echo $page->title; ?></title>

	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">

	<!-- We highly recommend you use SASS and write your custom styles in sass/_custom.scss.
		 However, there is a blank style.css in the css directory should you prefer -->
	<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/gumby.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/style.css" />

	<script src="<?php echo $config->urls->templates?>js/libs/modernizr-2.6.2.min.js" /></script>
</head>

<body>

	<div id="wrapper">
		<div class="row social">
			<div class="two columns socialmedia">			
				<?php echo $header->social_icons; ?>
			</div>
			</div>
		
		<div class="row top">
							<div class="balk"></div>

			<div class="three columns logo"><?php echo $header->logo; ?> </div>
			<div class="nine columns navigation">
				<ul class="main-nav">
					<?php
						    $root = $pages->get("/");
						    $children = $root->children;
						    $children->prepend($root);
						    foreach($children as $child) {
						        echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
						    }
   						?>
					
				</ul>
			</div> <!-- END NAVIGATION -->
		</div>

	<div class="row header">
				<div class="twelve columns header-image"><img src="<?php echo $header->header->eq(0)->getThumb('thumbnail');?>" /> </div>
			</div><!-- END HEADER -->
		</div><!-- END TOP -->
		<div class="clear"></div>

He said it was because the home.php was including the header.inc, but the variables were loading pages instead of $head or something like that.

Its hard to explain in english. Hope you guys will understand it with this code above.

Link to comment
Share on other sites

Your last code makes a lot more sense sense. All previous code and errors didn't had any of $header... Then you solution was 

<php $header=$pages->get('pagenumber'); ?>

Which makes no sense. :) $header wasn't anywhere in header.inc and further $pages->get("pagenumber") doesn't do anything in PW.

Now using a integer

<php $header=$pages->get(1012); ?> // '1012' works but looks wierd as it's a string and not a number 

Is a different story as it will load a page with ID 1012. And with the new header include you show posted there's suddenly a $header->scoial_icons etc. Anyway happy your colleague was able to help you out  :)

  • Like 1
Link to comment
Share on other sites

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...