Jump to content

Can't get delayed output working in templates


specialk
 Share

Recommended Posts

I've set up our template according to the instructions at https://processwire.com/docs/tutorials/how-to-structure-your-template-files/page4 but I can't get it to work, unfortunately.

I have created 3 files:

_init.php

_main.php

home.php

_init.php defines a couple of variables

home.php overrides them

_main.php uses them within a design

My page is set to use the home template, but unfortunately I'm not getting any output. My home.php only overrides two variables - It doesn't not output its own data. The ONLY way I can make my homepage show data is to actually add it to home.php, ie

<?php
$var1 = $page->whatever;
$var2 = $page->whatever2;
//If I leave it with just the above, nothing happens
//But with the below line, I'll get 'test' and nothing else output.
echo 'test';

?>

My installation originally started out with home.php holding the entire design and _init.php and _main.php not existing. Is there some sort of cache I need to clear so that ProcessWire will see the _init and _main files?

The only way that I can actually get the correct output with this setup is to set home.php up like so

<?php
include '_init.php';

$var1 = $page->whatever;
$var2 = $page->whatever2;

include '_main.php';
?>

But that sort of defeats the purpose of the autoloading _init and _main feature that Processwire has.

Link to comment
Share on other sites

I may be wrong, but the naming scheme you are using is more like the default profile for PW.  If you were trying to do the delayed output, the instructions you referenced in the link are highly detailed on how to achieve that design.

It also wouldn't hurt to have more detailed information about your installation (Front-end framework used, version of PW, PHP, etc..) and what you are trying to achieve.

The code that you showed would output the text "test".

Link to comment
Share on other sites

OK, I just read the link that I posted and that isn't what I meant to link to. I just found the documentation page that I had read earlier - http://processwire.com/docs/tutorials/default-site-profile/page3 

We are developing using PHP 5.6 and the latest version of Processwire. We are seasoned PHP vets but new to ProcessWire and it was our understanding that having a _init.php and _main.php would lead the loading pattern of _init.php --> template.php --> _main.php and I'd rather not dig through the source code to figure out how it works / why it's not working for us. I was hoping that someone here might have some insight.

The code I posted above should not simply output 'test' as _main.php is an entire coded design that makes use of the $variables $that $we $have $defined in _init.php and $overridden in home.php

Basically - Why isn't PW autoloading the _init and _main files like the docs say it should? 


See https://processwire.com/talk/topic/7743-getting-my-head-around-the-intermediate-default-profile/?p=75043 - This is EXACTLY how we have our template set up, except it doesn't actually work unless we manually include _init.php and _main.php from the template.php file, which defeats the purpose.


And I just figured out the solution. If you want to use this style of templating, you have to update config.php's

$config->prependTemplateFile = '_init.php';
$config->appendTemplateFile = '_main.php';

Since we started with an empty template, those variables had to be updated from their '' value to the new values.

  • Like 1
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...