Ivan Gretsky Posted August 12, 2019 Share Posted August 12, 2019 Good evening (at least in my part of the world)! Is there a way to call halt() method from within a function in a template file? Link to comment Share on other sites More sharing options...
rick Posted August 12, 2019 Share Posted August 12, 2019 $this->halt(); As shown at the bottom of this thread. Is this what you are referring to? Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted August 14, 2019 Author Share Posted August 14, 2019 Yes, that is what I need to do. But in a function, where $this (which contains current template) is out of scope. Link to comment Share on other sites More sharing options...
bernhard Posted August 14, 2019 Share Posted August 14, 2019 Hm... For whatever reason the halt() method is protected and can therefore only be called from within the class or derived ones. Passing $this to the function does not work and I don't know of any solution other than using die() or exit() in this case. Or just let the function return false and halt outside in that case: function foo() { if(...) return false; echo 'foo bar'; } if(foo() === false) return $this->halt(); echo 'something more'; 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted August 15, 2019 Author Share Posted August 15, 2019 Thanks @bernhard! I did try about the same tricks to make it work and ended up just doing exit(0); Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted April 28, 2023 Share Posted April 28, 2023 There's no way to halt a template rendering from within my custom module's ready method? return $this->halt(); doesn't work ? Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted May 23, 2023 Share Posted May 23, 2023 How would I halt output of a template file using return $this->halt(); but with that code not actually appearing in the template file itself? In short, I want to halt output of a template file at some point using the halt method described, but I want to have it be done more flexibly, meaning I want that code to exist within my ready.php for example (or just somewhere not in the template file). What's the best way to do this? I don't want to use exit because it has unintended consequences. Link to comment Share on other sites More sharing options...
bernhard Posted May 24, 2023 Share Posted May 24, 2023 I think your question totally depends on how you have built your frontend. When using RockFrontend for example you could hook into RockFrontend::render() and then trigger the halt() before or after any portion of code has been rendered. 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