Jump to content

Repeated Fields in Delayed Output Strategy


cssabc123
 Share

Recommended Posts

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?  
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">  supposed to be in head tag before any css. That means in delayed output I have to put it in _main.php, however I need to use it in my template say basic-page.php. Is pure-min.css visible in the template?

Edited by LostKobrakai
Merged into the other delayed output topic
Link to comment
Share on other sites

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.

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