bernhard Posted July 11, 2019 Share Posted July 11, 2019 I'm working on a new markup module and want to have the API available in the included file. I know I can do that: $code = $this->files->render('myfile', [ 'page' => $this->page, 'pages' => $this->pages, ... ]); Then I'd have $page and $pages in my file, but I'd need to list all available API variables manually and keep them in sync with the API. Other solution: $code = $this->files->render('myfile', [ 'that' => $this, ]); Then I'd have all API variables available from $that->page, $that->pages etc. Can I get best of both? Thx ? Link to comment Share on other sites More sharing options...
ukyo Posted July 11, 2019 Share Posted July 11, 2019 @bernhard if you are using ProcessWire 3 and if useFunctionsApi enabled you can call all api functions in rendered files directly. 3 Link to comment Share on other sites More sharing options...
markus_blue_tomato Posted July 11, 2019 Share Posted July 11, 2019 Use wire('all') Example from our production code: $factory = $modules->get('TemplateEngineFactory'); echo $factory->render('chunks/bodyCta.tpl', array_merge( (array) wire('all'), (array) [ "title" => $title, "text" => $text, "href" => $href ] )); 6 Link to comment Share on other sites More sharing options...
bernhard Posted July 11, 2019 Author Share Posted July 11, 2019 1 hour ago, Markus (Blue Tomato) said: Use wire('all') Awesome! Exactly what I was looking for, thx ? Maybe also interesting for you @kongondo (or are you already using it like this in your module?) Thx for the idea @ukyo but I need that feature for backend development and I can't rely on the functions API and it's also only recommended for use on the frontend. Link to comment Share on other sites More sharing options...
Robin S Posted July 21, 2019 Share Posted July 21, 2019 On 7/12/2019 at 4:16 AM, bernhard said: I'm working on a new markup module and want to have the API available in the included file. From the $files->render() docs: Quote Please note that all template files automatically receive all API variables already (you don't have to provide them). 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 22, 2019 Author Share Posted July 22, 2019 On 7/21/2019 at 6:41 AM, Robin S said: Please note that all template files automatically receive all API variables already (you don't have to provide them). Thx Robin ? Didn't know that, just tried it and it also works for $files->include() ? 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