Jump to content

Recommended Posts

Hello here is my current page all I am trying to do is use includes instead of writing what $main = this is a template varible in template.php the speech marks must be wrong and without them the page fails, anyone any idea's?

 

<?php 

$site_title = "Restaurants, Pubs, Places to Eat, Food & Drink Dine with us"; 
$page_title = "TEST"; 

$main = "include('dining_include.php')"; (This is where I'm stuck) 

require('include/nav2.php'); 

$template = file_get_contents('include/template.php'); 

$search = array('¦{PAGE_TITLE}¦', 
'¦{MAIN_MENU}¦', 
'¦{MAIN}¦' 

); 
$replace = array("$site_title - $page_title", 
$main_menu, 
$main, 

); 

$output = preg_replace($search, $replace, $template); 

echo $output; 
?> 

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/
Share on other sites

You can also just add the include into your array.

 

<?php

 

function foo()

{

    global $color;

 

    include 'vars.php';

 

    echo "A $color $fruit";

}

 

 

 

The thing with the "include" is once you added it to your PHP file it is automatically included anywhere you call for something that is in the include file. That also includes the Vars that are in the "include PHP file" that you call.

 

 

Hope that helps, or makes sense.

 

Brett

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-330997
Share on other sites

thank you for the speedy reply but no that still causes problems

 

$main = include 'dining_include.php';

 

I need the $main =  because in template.php this is th varible for the main place holder

it works if I do something like this

 

$main = "content here ...";  (but I need includes to show dynamic content)

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-330999
Share on other sites

I may of got a little confused here by your example I have adjusted it

the content appears but outside a template and in the template it shows 1

so I must be nearly there, just have something slightly wrong here ?

 

$main = include('dining_include.php');

 

function dining()

{

    global $main;

 

    include 'dining_include.php';

 

    echo "$main";

}

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331021
Share on other sites

It is not necessary (or suggested) to use it as a function. Stick with

include 'dining_include.php';

 

I'm not sure what you are trying to do. Include doesn't have a return function unless you put one in the code of the included file. If you don't have a return statement in dining_include.php, all that first line is doing is setting $main = null. Later on, you echo null. All include does is take a php file from another and effecively "copy and pastes" it into the code that is callig it, at that location. Put the statement where you want the code in dining_include.php to be executed in the main php file.

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331041
Share on other sites

Ok not sure if you know what I am trying to do, I will try to explain more clearly

 

this works and shows "some content here about this page" inside the template

 

$main = "some content here about this page";

 

this one shows the correct content but above the template and in the template now shows the number 1

all I am trying to do here is use a include within $main so that it shows within the template it does not matter what the include file is if it be aline of text or a dynamic page the content displays above the template  ???

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331052
Share on other sites

I still am not clear on what you are trying to do. What I think is happening is that $main is not getting set to anything usefull. The reason it is outputting content is because you do have the correct include statment inside your dining() function. When you use include, it puts the contents wherever you use include. There is no reason to set a variable unless the included file is returning a value. Like I said before, if you want to include it only in a specific spot, just put the include where you want it to be included. If it is something more complicated than just including the content of the file in your page, it would be helpful if you posted the code of the included file, as $username suggested.

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331056
Share on other sites

Ok then

$main = include 'content1.php';   (this can be any file example below)

 

I could work the below without using include like this and it world show up in the template

but this would be a problem for a dynamic page with all the script css etc.

so I am using include for this, it seems to me the template var only works in the correct place with something like this $main= ""; but I cannot put an include in between speece marks  ???

 

$main = "<p>content here for page </p>
<p>...................................................<br />
................................................ </p>";

 

content1.php code below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>content here for page </p>
<p>...................................................<br />
................................................ </p>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331068
Share on other sites

Ok let me give this one more shot.

 

This is your current code

 

$main = include('dining_include.php');

 

function dining()

{

    global $main;

 

    include 'dining_include.php';

 

    echo "$main";

}

-----------------

As far as I know you can not do a Var = include. if you want to make a page show with in a var you may have to

 

 

require_once( 'templates/'. $cur_template .'/index.php' );

 

{

    global $cur_template;

 

    include 'dining_include.php';

 

    echo "$cur_template";

}

 

 

Hope this helps.

You may wanna check into something else to get a PHP page to echo.

 

Brett

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331071
Share on other sites

this is the contents of template_includes hopefully this will explain how the $main var has been created

username your code now inserts the content below the template but not in the middle

 

<?php 
//require('include/header.php');
//require('include/strapline.php');
//require('include/footer.php');

require('include/nav2.php');

// First we read the contents of the template.php file as the variable $template.
$template = file_get_contents('include/template.php');

// Now we do a search and replace on $template inserting content where the keywords were placed
// We do this with 2 arrays, one for search and one for replace.
// We then use the preg_replace function to make the changes and create an output variable

$search = array('|{PAGE_TITLE}|',
'|{MAIN_MENU}|',
'|{MAIN}|'    // this is where I am trying to get the content to display
//'|{HEADER}|',
//'|{FOOTER}|',
//'|{STRAPLINE}|'

);
$replace = array("$site_title - $page_title",
$main_menu,
$main,  // use this var to display the content
//$header,
//$footer,
//$strapline
);

$output = preg_replace($search, $replace, $template);

echo $output;
?>

 

 

and then of course the actual template file include/template.php

<html>
<head>
<title>
{PAGE_TITLE}
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body class="thrColHybHdr">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="13%" background="../newdining/template/dinewithus_r1_c1_2.gif"><img src="../newdining/template/dinewithus_r1_c1.gif" width="156" height="153" /></td>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="../newdining/template/dinewithus_r1_c2.gif" width="100" height="103"></td>
        <td width="100%" background="../newdining/template/dinewithus_r1_c3.gif"> </td>
      </tr>
      <tr>
        <td height="50" colspan="2" valign="top" background="../newdining/template/dinewithus_r2_c2.gif"><table width="100%" border="0" align="right" cellpadding="2" bgcolor="#CC3429">
          <tr>
            <td><div id="topleft">
              <div align="center" class="topleft"><strong>News | Testimonials | Links | Local Producer Search</strong></div>
            </div></td>
            <td><div align="right">
                <div align="center" class="style11">
                  <div align="right" class="style16">
                    <div align="center" class="style16"><span class="topright"><strong>The Dining & Eating Out Guide for the Midlands</strong></span></div>
                  </div>
                </div>
            </div></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="top" background="../newdining/template/dinewithus_r5_c1.gif"><div id="sidebar1"> <br />
        {MAIN_MENU}
        <div align="center">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><p align="center"><font color="#99cccd"><a href="http://www.churchill-vintners.co.uk/" target="_blank"><br />
                <img src="images/ads/1churchill.jpg" alt="" width="100" height="200" hspace="5" vspace="5" border="0" /></a><a href="http://www.thefoodie.co.uk" target="_blank"><br />
                        <img src="images/ads/Foodie link.jpg" width="101" height="144" hspace="5" vspace="5" border="0" /></a><a href="http://www.osminolives.co.uk" target="_blank"><br />
                </a></font><font color="#99cccd"><a href="http://www.classic-wine.co.uk" target="_blank"><img src="images/ads/classic-wine.jpg" width="100" height="160" hspace="5" vspace="5" border="0" /></a></font><font color="#99cccd"><a href="http://www.dinewithus.co.uk" target="_blank"><br />
              </a></font><font color="#99cccd"><a href="http://www.thefoody.com" target="_blank"><img src="images/ads/foody_com.jpg" width="100" height="95" hspace="5" vspace="5" border="0" /></a></font></p></td>
              <td width="22"> </td>
            </tr>
          </table>
        </div>
    </div></td>
    <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top">{MAIN}</td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331082
Share on other sites

i see what you're trying to do, but i don't think you'll be able to do it with your current template setup.  if you want the PHP code in dining_include.php to be executed only when the $template is output, you'll need to use eval().  otherwise, to simply assign the content of dining_include.php to $main, you'll need to use file_get_contents(), as you are with the template file.

 

perhaps a few more details about dining_include.php and what it contains would be helpful if this isn't what you're after.

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331093
Share on other sites

dining_includes.php code below this now shows the content but something is blocking the XML from displaying ?

 

$main = file_get_contents ('dining_include.php');

 

<link href="css/template.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://www.dinewithus.co.uk/templates/dinewithus/css/template_css.css"type="text/css"/>
<script src="SpryAssets/xpath.js" type="text/javascript"></script>
<script src="SpryAssets/SpryData.js" type="text/javascript"></script>
<script src="SpryAssets/SpryEffects.js" type="text/javascript"></script>
<script src="SpryAssets/SpryPagedView.js" type="text/javascript"></script>
<script src="SpryAssets/SpryURLUtils.js" type="text/javascript"></script>
<script src="SpryAssets/SpryDataExtensions.js" type="text/javascript"></script>
<script src="SpryAssets/SpryAutoSuggest.js" type="text/javascript"></script>
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//-->

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

</script>

<script src="include/js/vars.js" type="text/javascript"></script>
<script src="include/js/functions.js" type="text/javascript"></script>
<link href="SpryAssets/SpryAutoSuggest.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--

.mybox { width:90px; height:115px; border-color:black; border-style:solid; border-width:1px; padding:0px; }
-->
</style>

<link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style7 {
font-size: 16px;
font-weight: bold;
}
-->
</style>
<div>
  <div id="topnew">

    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  
  <tr>
    <td><div align="center">
        <?php include("include/map-search.php"); ?>
    </div></td>
  </tr>
  <tr>
    <td><div align="center">
      <div id="TabbedPanels2" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">SEARCH BY FOOD STYLE</li>
          <li class="TabbedPanelsTab" tabindex="0">SEARCH BY FACILITIES</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="TabbedPanelsContent">
            <table width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
              <tr>
                <td width="20" bgcolor="#F9F9F9"><p class="style1">
                    <input name="traditional" type="checkbox" id="traditional" onclick="ToggleFilter(this.checked, traditional);" value="" />
                </p></td>
                <td width="108" bgcolor="#FFF7AA"><strong><span class="style54"><span class="style58"><strong>Traditional</strong></span></span></strong></td>
                <td width="20" bgcolor="#F9F9F9"><input name="european" type="checkbox" id="european" onclick="ToggleFilter(this.checked, european);" value="" /></td>
                <td width="108" bgcolor="#FFFFCC"><span class="style55"><span class="style1">European</span></span></td>
                <td width="20" bgcolor="#F9F9F9"><input name="finedining" type="checkbox" id="finedining" onclick="ToggleFilter(this.checked, finedining);" value="" /></td>
                <td width="108" bgcolor="#FFF7AA"><span class="style55"><strong><span class="style54"><strong><span class="style58">Fine Dining</span></strong></span></strong></span></td>
                <td width="20" bgcolor="#F9F9F9"><input name="fish" type="checkbox" id="fish" onclick="ToggleFilter(this.checked, fish);" value="" /></td>
                <td width="108" bgcolor="#FFFFCC"><strong><span class="style54"><span class="style58"><strong><strong>Fish</strong></strong></span></span></strong></td>
                <td width="20" bgcolor="#F9F9F9"><input name="cafe" type="checkbox" id="cafe" onclick="ToggleFilter(this.checked, cafe);" value="" /></td>
                <td width="108" bgcolor="#FFF7AA"><strong><span class="style54"><span class="style58">Cafe Culture</span></span></strong></td>
                <td width="20" bgcolor="#F9F9F9"><input name="african" type="checkbox" id="african" onclick="ToggleFilter(this.checked, african);" value="" /></td>
                <td width="114" bgcolor="#FFFFCC"><span class="style58">African</span></td>
              </tr>
              <tr>
                <td bgcolor="#F9F9F9"><input name="modern" type="checkbox" id="modern" onclick="ToggleFilter(this.checked, modern);" value="" /></td>
                <td bgcolor="#FFF7AA"><span class="style1"><strong>Modern British</strong></span></td>
                <td bgcolor="#F9F9F9"><input name="asian" type="checkbox" id="asian" onclick="ToggleFilter(this.checked, asian);" value="" /></td>
                <td bgcolor="#FFFFCC"><span class="style58">Asian</span></td>
                <td bgcolor="#F9F9F9"><input name="pubbar" type="checkbox" id="pubbar" onclick="ToggleFilter(this.checked, pubbar);" value="" /></td>
                <td bgcolor="#FFF7AA"><span class="style58">Pub/Bar</span></td>
                <td bgcolor="#F9F9F9"><input name="veg" type="checkbox" id="veg" onclick="ToggleFilter(this.checked, veg);" value="" /></td>
                <td bgcolor="#FFFFCC"><span class="style58">Veg</span></td>
                <td bgcolor="#F9F9F9"><input name="speciality" type="checkbox" id="speciality" onclick="ToggleFilter(this.checked, speciality);" value="" /></td>
                <td bgcolor="#FFF7AA"><strong><span class="style54"><span class="style58">Speciality</span></span></strong></td>
                <td bgcolor="#F9F9F9"><input name="carvery" type="checkbox" id="carvery" onclick="ToggleFilter(this.checked, carvery);" value="" /></td>
                <td bgcolor="#FFFFCC"><span class="style1"><strong>carvery</strong></span></td>
              </tr>
            </table>
          </div>
                <div class="TabbedPanelsContent">
            <table width="100%" border="1" align="center" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF">
              <tr>
                <td bgcolor="#FFFFCC"><div align="center"><span class="style1">T/B/A</span> </div></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/covered_smoking.jpg" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Smoking Al Fresco</td>
                <td bgcolor="#FFFFCC"><input name="disabled_access_facilities" type="checkbox" id="disabled_access_facilities" onclick="ToggleFilter(this.checked, disabled_access_facilities);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/wc.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Disabled Access </td>
                <td bgcolor="#FFFFCC"><input name="real_ales" type="checkbox" id="real_ales" onclick="ToggleFilter(this.checked, real_ales);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/ra.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Real Ales</td>
                <td bgcolor="#FFFFCC"><input name="open_fires" type="checkbox" id="open_fires" onclick="ToggleFilter(this.checked, open_fires);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/of.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Open Fire</td>
                <td bgcolor="#FFFFCC"><input name="with_accommodation" type="checkbox" id="with_accommodation" onclick="ToggleFilter(this.checked, with_accommodation);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/wa.gif" width="35" height="25" hspace="2" vspace="2" align="absmiddle" />Accommodation</td>
              </tr>
              <tr>
                <td bgcolor="#FFFFCC"><div align="center">
                    <input name="award_recognitions" type="checkbox" id="award_recognitions" onclick="ToggleFilter(this.checked, award_recognitions);" value="" />
                </div></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/ros.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Award Winning</td>
                <td bgcolor="#FFFFCC"><input name="garden" type="checkbox" onclick="ToggleFilter(this.checked, garden);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/gar.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Garden area</td>
                <td bgcolor="#FFFFCC"><input name="function_room" type="checkbox" id="function_room" onclick="ToggleFilter(this.checked, function_room);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/fr.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Function Room</td>
                <td bgcolor="#FFFFCC"><input name="speciality_diet_friendly" type="checkbox" id="speciality_diet_friendly" onclick="ToggleFilter(this.checked, speciality_diet_friendly);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/sd.gif" width="25" height="25" hspace="2" vspace="2" align="absmiddle" />Special Diets</td>
                <td bgcolor="#FFFFCC"><input name="private_dining" type="checkbox" id="private_dining" onclick="ToggleFilter(this.checked, private_dining);" value="" /></td>
                <td bgcolor="#FFF7AA"><img src="http://www.dinewithus.co.uk/dining/fac/pd.gif" width="35" height="25" hspace="2" vspace="2" align="absmiddle" />Private Dining</td>
              </tr>
            </table>
          </div>
        </div>
      </div>
      <div align="center" class="style77"></div>
    </div>
      </td>
  </tr>
</table>

    
    
<div align="center"></div>
  </div>
  <div id="sidebar2">
    <div align="center">
      <img src="images/map.jpg" width="120" height="110" vspace="4" />
      <table border="0" align="center">
        <tr>
          <td><form action="../dining/outlet.php" method="post" name="accountname" id="accountname">
                <div align="center"><br />
                  <span class="style7">OR</span><br />
                  Select town below!<strong><br />
              </strong> </div>
              </form></td>
        </tr>
        <tr>
          <td background="new-template/dinewithus_bookmark2.jpg"><div align="center">
              <ul spry:region="dsTowns" spry:repeatchildren="dsTowns">
                <li onclick="" spry:select="selected" spry:hover="hover">
                  <div align="center"><span class="mainlevel2"><a href="dining2.php?county_url={county_url}&twn_url={twn_url}">{twn}</a> </span></div>
                </li>
              </ul>
          </div></td>
        </tr>
      </table>
      <div align="left"></div>
    </div>
  </div>
  <br />
<div id="mainContentNew">
  <div id="TabbedPanels1" class="TabbedPanels">
    <ul class="TabbedPanelsTabGroup">
      <li class="TabbedPanelsTab" tabindex="0" spry:region="dsShropshire">{twn} Results</li>
      <li class="TabbedPanelsTab_Offers" tabindex="0">Offers</li>
      <li class="TabbedPanelsTab_Events" tabindex="0">Events</li>       				      
      <li class="TabbedPanelsTab_Menus" tabindex="0">Menus</li>
    </ul>
    <div class="TabbedPanelsContentGroup">
      <div class="TabbedPanelsContent">
        <?php include("include/listings.php"); ?>
      </div>
      <div class="TabbedPanelsContent">
        <?php include("include/offers.php"); ?>
      </div>
      <div class="TabbedPanelsContent">
        <?php include("include/events.php"); ?>
      </div>
      <div class="TabbedPanelsContent">
        <?php include("include/menus.php"); ?>
      </div>
    </div>
  </div>

</div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<!-- end #container -->
</div>

<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
var as1 = new Spry.Widget.AutoSuggest('productSample', 'productMenu', 'dsLive', 'accountname', 'twn');
var TabbedPanels2 = new Spry.Widget.TabbedPanels("TabbedPanels2");
//-->
</script>

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331112
Share on other sites

the PHP within the dining_includes.php will not be executed, since it's being echoed as a string (it doesn't parse the PHP when it is obtained through file_get_contents()).  in order to have those includes parsed within the dining_includes.php file, you'll need to include it directly rather than spitting it out as a string.  it's not really compatible with your template system.

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331116
Share on other sites

Maybe this is not the best way to apply the template

all I am trying to do is apply the template for each page without having to include the template each time

and without using smarty template engine there must be an easier way to do this otherwise I have to change the template several times on all pages  ???

Link to comment
https://forums.phpfreaks.com/topic/66173-template-help/#findComment-331121
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.