Jump to content

Flash of unstyled text in a special case of complex templatre rendering


theoretic
 Share

Recommended Posts

Hi guys and ladies! And thanks for Processwire!

It appears i've found a very specific case of template rendering behaviour. The steps to reproduce this:

  1. Enable markup regions in site/config.php:
    $config->useMarkupRegions = true;
  2. Let's suppose we have a data file templates/data.php with the content like this:
    <?
    return ['name'=>'value'];
    ?>

    This file is included into a template file default.php in the following way:

    <?
    //getting data from external file
    
    $data = include 'data.php';
    
    //the rest of template logic and output
    ?>
    
    <html>
      <?=$data['name']?>
    </html>

     

In this case the pages with default.php template are being rendered in a very strange way (at least in fresh Firefox). A flash of unstyled content, followed by repaint and rendering of styled content. It's very likely that the "return - include" construction causes some output before all the page html is fully prepared.

It's easy to "fix" this behaviour:

<?
//inisializing $data in-place

$data = ['name'=>'value'];

//the rest of template logic and output
?>

<html>
  <?=$data['name']?>
</html>

I like that "include-return" code approach and use it in many of my projects, and it was always giving no problem with page rendering. With the markup regions turned on, it becomes a problem. Are there any ideas how to use both "include-return" and markup regions together with no rendering trouble? And what could cause that trouble? Thanks in advance!

Link to comment
Share on other sites

Maybe you can wrap a output buffer around it, (in a site/_main.php) ?

ob_start();

// do all your template and include code

// and finally flush it to the browser all at once:
echo ob_get_clean();

 

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