for some reason, the content of my layout template file (in the layout subdirectory) is being output prior to the content of the page template file (in the theme subdirectory), resulting in invalid html structure.

any ideas what would cause this behavior?

thanks for any thoughts.

Accepted answer

ok, i think i found the problem. you could not see it in what i had posted above. some of the init code for the page is using output buffering, and i was using ob_clean() to finish. obviously backdrop also uses output buffering, and i had created a conflict there. i just changed that to ob_end_clean(), and it seemed to clear up the issue.

thanks for trying to help!

Comments

Template problem it sounds like .Can you post the template file?

here is the layout file:

<?php
$names = getGlobalNames();
foreach ($names as $name) { global ${$name}; }
eval($initCode);
?>
<div class="container layout--moscone-flipped <?php print implode(' ', $classes); ?>"<?php print backdrop_attributes($attributes); ?>>

  <div id="header">
    <div id="site-name">
      <a href="" title=""><img src="/img/logo-small.jpg" alt="" title=""  /></a>
    </div>
    <?php require(backdrop_get_path('theme', 'mbr') . '/templates/main-menu.php'); ?>
  </div>  

  <?php if ($content['header']): ?>
    <header class="l-header" role="banner" aria-label="<?php print t('Site header'); ?>">
      <div class="l-header-inner container container-fluid">
        <?php print $content['header']; ?>
      </div>
    </header>
  <?php endif; ?>

  <div class="l-wrapper">
    <div class="l-wrapper-inner container container-fluid">

      <?php if ($messages): ?>
        <div class="l-messages" role="status" aria-label="<?php print t('Status messages'); ?>">
          <?php print $messages; ?>
        </div>
      <?php endif; ?>

      <?php if ($tabs): ?>
        <nav class="tabs" role="tablist" aria-label="<?php print t('Admin content navigation tabs.'); ?>">
          <?php print $tabs; ?>
        </nav>
      <?php endif; ?>

      <?php print $action_links; ?>

      <div class="l-middle row">
      
        <table id="bodytab"><tr><!-- begin main body table/row -->
          <td valign="top" id="body-content">
          <?php
            if (isset($pageFiles['content']))
            {   
              //$modulePrefix = $_SERVER['DOCUMENT_ROOT'] . '/' . backdrop_get_path('module', 'mbr_crypto') . '';
              $templatePrefix = $_SERVER['DOCUMENT_ROOT'] . '/' . backdrop_get_path('theme', 'mbr') . '/templates';
              $contentFile = $pageFiles['content'];
              $contentFile = "$templatePrefix/$contentFile";
              
              if (is_file($contentFile))
              { require_once($contentFile); }
              else
              {
                echo "$contentFile not found";
              }
            }
            else
            {
              echo $content['content'];
            }
            ?>
          </td> <!-- end content cell -->
        
          <td valign="top" id="body-sidebar">
            <?php print $content['sidebar']; ?>
          </td> <!-- end sidebar cell -->
        </tr></table><!-- end main body table/row -->
        
      </div> <!-- .l-middle -->

    </div><!-- /.l-wrapper-inner -->
  </div><!-- /.l-wrapper -->

  <?php if ($content['footer']): ?>
    <footer class="l-footer"  role="footer">
      <div class="l-footer-inner container container-fluid">
        <?php print $content['footer']; ?>
      </div>
    </footer>
  <?php endif; ?>
</div><!-- /.layout--moscone-flipped -->

 

 

 

 

and here is the page template file:

<?php
$names = getGlobalNames();
foreach ($names as $name) { global ${$name}; }

?><!DOCTYPE html>
<html<?php print backdrop_attributes($html_attributes); ?>>
  <head>
    <?php print backdrop_get_html_head(); ?>
    <?php print backdrop_get_css(); ?>
    <?php print backdrop_get_js(); ?>
   
  <title><?php echo $pageTitle ?></title>
  <meta name="description" content="<?php echo $metaDescription ?>" />
    
  </head>
  <body class="<?php print implode(' ', $classes); ?>"<?php print backdrop_attributes($body_attributes); ?>>
    <?php print $page; ?>
    <?php print $page_bottom; ?>
    <?php print backdrop_get_js('footer'); ?>
  </body>
</html>

i should note that on another site i am using the same layout and theme, with no problem. i am still comparing code to see what is different.

here is the (beginning of) the generated html:

<div class="container layout--moscone-flipped layout">

  <div id="header">
    <div id="site-name">
      <a href="" title=""><img src="" alt="" title=""  /></a> 
    </div>
    <div id="newmenudiv">
<ul id="nav"> 
<li class=""></li>
<li class=""></li>
<li class=""></li>
<li class=""></li>
<li class=""></li>
</ul>
</div>

  </div>  

  
  <div class="l-wrapper">
    <div class="l-wrapper-inner container container-fluid">

      
              <nav class="tabs" role="tablist" aria-label="Admin content navigation tabs.">
          <h2 class="element-invisible">Primary tabs</h2><ul class="tabs primary"><li class="active"><a href="/home" class="active">View<span class="element-invisible">(active tab)</span></a></li>
<li><a href="/node/3/edit">Edit</a></li>
</ul>        </nav>
      
      
      <div class="l-middle row">
      
        <table id="bodytab"><tr><!-- begin main body table/row -->
          <td valign="top" id="body-content">
          <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>....

ok, i think i found the problem. you could not see it in what i had posted above. some of the init code for the page is using output buffering, and i was using ob_clean() to finish. obviously backdrop also uses output buffering, and i had created a conflict there. i just changed that to ob_end_clean(), and it seemed to clear up the issue.

thanks for trying to help!