Adam Kiss Posted November 26, 2013 Share Posted November 26, 2013 Hey all, I have a quick (?) question here. I am using prepend/appendTemplateFile in my config for site's header/footer. When using URL segments, I throw 404 Exception for non-existing URL segments, which is all well. The problem is, that at the moment of 'throw new…', there already is one page header rendered, and the exception renders it again for 404 page. Is there any way around this? Thanks. Edit: require_once for the append/prepend files solves this, so I opened issue on github: https://github.com/ryancramerdesign/ProcessWire/issues/282 Link to comment Share on other sites More sharing options...
ryan Posted November 30, 2013 Share Posted November 30, 2013 require_once isn't ideal for prepend/append template file settings. When you call $page->render(); you want to know that everything you expect to be included is included. A lot of us call render() methods on other pages, which a require_once() could break. If there are things that need to be require_once (like function or class definitions) you can always move those to another file and require_once them from your prependTemplateFile. My prependTemplateFile usually looks something like this: // initialize page regions with default values // this will be output eventually in _main.php $headline = $page->title; $browserTitle = $page->title; $body = $page->body; $sidebar = ''; // include shared function libraries require_once('./includes/finder.php'); require_once('./includes/render.php'); As for your particular case, it sounds like you've got some logic running after output has started. You want to move that logic to somewhere before output starts. Given that, prependTemplateFile is not an ideal place to output header markup. However, if you want to continue doing that, then you may be able to place this at the top of your prepend TemplateFile: if($page->name == 'http404') return; 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted December 5, 2013 Author Share Posted December 5, 2013 Thanks Ryan, seems that it is again that part of year where I have to revise what goes where in my PW installs 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now