We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Template won’t include when I also use php include

Development and Programming

justinviger's avatar
justinviger
36 posts
15 years ago
justinviger's avatar justinviger

I am working on a site that has the navigation as hidden template. But on one page the content is not within EE, but is in another database that someone else setup and they gave me a php include which brings in content from that database I assume.

The problem is the navigation isn’t showing up. When I delete the php include code the navigation shows up.

Here is the EE template code:

<?php include_once("inc/functions.local.inc.php"); ?>
<!DOCTYPE html>
<html lang="en">

<head>

<title>{site_name} - Riders Choice</title>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<link href="/assets/master.css" rel="stylesheet" type="text/css" />

</head>

<body class="readerschoice">

<div id="container">
<div id="header">
<div id="leaderboard">

<?php include("assets/php/leaderboard.php"); ?>

</div> <!-- / #leaderboard -->

<?php include("assets/php/secondarynav.php"); ?>

/assets/images/top_navs/readerschoice600x56.gif

<div id="earlug">

<?php include("assets/php/earlug.php"); ?>

</div> <!-- / #earlug -->
</div> <!-- / #header -->
<div id="navigationsidebar">

{embed="site/.nav"}

<div id="skyscraper">

<?php include("assets/php/skyscraper.php"); ?>

</div> <!-- / #skyscraper -->
</div> <!-- / #navigationsidebar -->
<div id="content">

<h1>Riders Choice</h1>

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

</div> <!-- / #content -->
<div id="advertsidebar">
<div id="bigbox">

<?php include("assets/php/bigbox.php"); ?>

</div> <!-- / #bigbox -->
<div id="quicklinks">

<h2>RidersWest quick links</h2>

<?php
$categories = '';
$zone = 0;
$adsizes = '4';
make_quicklink_listing_rw($categories, $zone, $adsizes);
?>

</div> <!-- / #quicklinks -->
<div id="sidebars">

<?php include("assets/php/sidebars.php"); ?>

</div> <!-- / #sidebars -->
</div> <!-- / #advertsidebar -->

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

</div> <!-- / #container -->

<?php include("assets/php/googleanalytics.php"); ?>

</body>

</html>

As you can see there are a lot of php includes. Those are now setup as hidden templates instead of php includes, but on this page I can’t switch to it.

       
John Henry Donovan's avatar
John Henry Donovan
12,339 posts
15 years ago
John Henry Donovan's avatar John Henry Donovan

Justin,

try including the full server path to these includes

       
justinviger's avatar
justinviger
36 posts
15 years ago
justinviger's avatar justinviger
Justin, try including the full server path to these includes

I changed some of the PHP includes to have the full path and they are still working.

I also changed the other PHP includes to global variables and embeded templates to be closer to what I am actually trying to do.

As of now the PHP part of the template is working but none of global variables or embeded templates are.

Here is the new code:

<?php include_once("/home/koocanus/public_html/riderswestmag.com/inc/functions.local.inc.php"); ?>
<!DOCTYPE html>
<html lang="en">

<head>

<title>{site_name} - Riders Choice</title>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<link href="/assets/master.css" rel="stylesheet" type="text/css" />

</head>

<body class="readerschoice">

<div id="container">
<div id="header">
<div id="leaderboard">

{leaderboard}

</div> <!-- / #leaderboard -->

{embed="site/secondarynav.php"}

/assets/images/top_navs/readerschoice600x56.gif

<div id="earlug">

{earlug}

</div> <!-- / #earlug -->
</div> <!-- / #header -->
<div id="navigationsidebar">

{embed="site/nav"}

<div id="skyscraper">

{skyscraper}

</div> <!-- / #skyscraper -->
</div> <!-- / #navigationsidebar -->
<div id="content">

<h1>Riders Choice</h1>

<?php include("/home/koocanus/public_html/riderswestmag.com/inc/listing.readerschoice.inc.php"); ?>

</div> <!-- / #content -->
<div id="advertsidebar">
<div id="bigbox">

{bigbox}

</div> <!-- / #bigbox -->
<div id="quicklinks">

<h2>RidersWest quick links</h2>

<?php
$categories = '';
$zone = 0;
$adsizes = '4';
make_quicklink_listing_rw($categories, $zone, $adsizes);
?>

</div> <!-- / #quicklinks -->
<div id="sidebars">

{sidebars}

</div> <!-- / #sidebars -->
</div> <!-- / #advertsidebar -->

{embed="site/footer"}

</div> <!-- / #container -->

{analytics}

</body>

</html>

Here is the output page of that template.

       
Greg Salt's avatar
Greg Salt
3,988 posts
15 years ago
Greg Salt's avatar Greg Salt

Hi Justin,

What is actually in these included files? Is there any way that you can convert the contents of them to be snippets or copy the contents directly into the template?

Cheers

Greg

       
justinviger's avatar
justinviger
36 posts
15 years ago
justinviger's avatar justinviger
Hi Justin, What is actually in these included files? Is there any way that you can convert the contents of them to be snippets or copy the contents directly into the template? Cheers Greg

Here is the contents of the listing.readerschioce.inc.php file:

<?php 

include_once('db.inc.php');

$oderno = 0; $place_OR_header = ""; $award_OR_header = "";

$sql = "SELECT
            *
        FROM
            tbl_rw_readers_choice
        ORDER BY iOrder";
            
$rs  = @mysql_query($sql, $conn);

if (!$rs)
      {exit("Error in listing.readerschoice.inc.php");}

$num = mysql_num_rows($rs);

for ($i = 0; $i < $num; $i++){  
    
    $row = mysql_fetch_array($rs);

    $orderno           = $row['iOrder'];
    $place_OR_header = $row['vPlaceOrHeader'];
    $award_OR_header = $row['vAward'];
    
    if ($award_OR_header == "header") {
        if ($i > 1) {
            echo "                </table>\n";
        }    
        echo "                <h2>".htmlspecialchars($place_OR_header, ENT_QUOTES)."</h2>\n";
        echo "                <table>\n";
        echo "                    <tr>\n";
        echo "                        <th>Award</th>\n";
        echo "                        <th>Place</th>\n";
        echo "                    </tr>\n";
    } else {
        echo "                    <tr>\n";
        echo "                        <td>".$award_OR_header."</td>\n";
        echo "                        <td>".htmlspecialchars($place_OR_header, ENT_QUOTES)."</td>\n";
        echo "                    </tr>\n";
    }

    if ($i == ($num-1)) {
        echo "                </table>\n";
    }    

}

?>

Maybe I could copy that directly to the template. I don’t know. I didn’t set that up. Should I ask the person who did?

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
15 years ago
Lisa Wess's avatar Lisa Wess

The problem with PHP includes in either direction is that EE’s template groups aren’t real directories. You would need to include via URL which most hosts disallow.

Including your code in the template engine could have scoping issues.

My recommendation would be to consider integration via some sort of module. I don’t know what you are trying to bring together, but PHP in the templates is not likely to give you the full scope of what you need.

Because this kind of PHP and integration with an outside app is a customization outside of technical support, I’m going to move this down to Development and Programming for you.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.