Jump to content

Recommended Posts

Posted

I created the repeated fields for the building repeated fields example of processwire.

in _main.php I executed directlyforeach($page->buildings as $building) {    echo "<h2>{$building->title}</h2><p>";       echo "Height: {$building->feet_high} feet, ";    echo "Floors: {$building->num_floors}, ";    echo "Year built: {$building->year_built} </p>";} This works without placeholder variables in _init.php, and hence no template placeholder population. Not sure how the can be in placeholders.  So for the delayed output strategy it appears some output can/must not have placeholder variables?  
Posted

maybe you don't need to used delayed output?

it can make many things more trouble than it's worth.

Have you tried the simple include head/foot method.

  • Like 2
Posted

The delayed output is not much different from not using it. 

Instead of just echoing out content immediatelly (no matter if at once or in _header.php -> template.php -> footer.php

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<h1><?php echo $page->title; ?></h1>
</body>
</html>

you're going to construct the "content" of the page before any html is outputted.

// _init.php
$content = "";

// template.php
$content .= "<h1>$page->title</h1>";

// _main.php
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<?php echo $content; ?>
</body>
</html>

The difference it that you're temp. storing the content (or whatever types you use/need) is stored in a variable until it's echod. The main benefits are that it does allow for later alteration of markup and sometimes cleaner code. Essentially just don't use echo in your template files, but only with the placeholder variables in _main.php and you've delayed output.

  • Like 1
Posted

No. $content (as it's named in my example) will ever only be a string of markup. You'd build _main.php once and everything else happens in the template.php. You just part for part add markup to $content and in the end _main.php will just spit everything out what is in that variable. 

Posted

Delayed output is just another way to generate the full html markup, that is send to the browser. The browser won't get anything different, therefore everything js/css is unaffected of this. 

  • Like 1
Posted

the only snafu i encounter with delayed output is that i lose the syntax highlighting of the HTML when it's all inside quotes as well as no double cursor (in ST for example)...

though i do use it a lot when constructing repeating elements like table rows, lists, galleries..

also with delayed output you can store the markup into the wire cache.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...