marcin Posted September 18, 2012 Share Posted September 18, 2012 Hello, I'm working on simple newsletter module and I want to modify page source(different header, no navigation and sidebar) while sending email based on page. I need one of these: a) pass a variable to page(the same as isAjax works, eg. isNewsletter) b) render page using different template file and have no idea how to achieve one of above. I'm also wondering whether it's possible to get JSON response in admin? Module method ___executeXXX() prints whole page. Thanks, Marcin Link to comment Share on other sites More sharing options...
teppo Posted September 18, 2012 Share Posted September 18, 2012 Hello there! Without knowing exactly how your module works, I can only throw in general ideas - hope they're of some help: a) You could use a GET variable for this; example.com/example-page/?view=newsletter and then "if ($input->get->view == "newsletter") { ... }". b) There are many solutions for this one. Simple way would be fetching the content of your newsletter page ($newsletterPage = $pages->get('/page-uri-or-whatever')) and then including a file with your alternative markup (in which you use $newsletterPage instead of $page) wherever you wish to render the newsletter. Another method would be to play around with actual template files; see this post by Soma for an example. One slightly crude method to get JSON (or pretty much any other markup you need) out of a process module is to output it (echo, output buffering, whatever floats your boat) and then die() -- or exit() if you prefer it that way. There are cleaner ways to do this too, but hey -- it works 1 Link to comment Share on other sites More sharing options...
marcin Posted September 18, 2012 Author Share Posted September 18, 2012 Hello, thank for your reply Whole thread you mentioned, appeared to be very helpful, thanks a lot! It solved both: a) $somePage->set('variableName', value) b) $somePage->template->set('filename', 'differentTemplate.php'); You idea about returning JSON - pretty cool! PW community is really awesome. Link to comment Share on other sites More sharing options...
ryan Posted September 19, 2012 Share Posted September 19, 2012 If the request comes in through ajax, ProcessWire will detect it and your Process module can just return the content (JSON or whatever) that you want in the ajax. Basically, you don't need to do anything other than load the page with ajax and you should get what you want. 1 Link to comment Share on other sites More sharing options...
marcin Posted September 19, 2012 Author Share Posted September 19, 2012 @ryan, thanks for your reply. I'll try it. Another question - is there some easy way to use PageSelect field? Module has it's own page in admin, so I probably can't easily add this kind of field to 'admin' template. The only thing I need is selected page ID. Thanks! Link to comment Share on other sites More sharing options...
ryan Posted September 20, 2012 Share Posted September 20, 2012 Here's one way that you could do that from your module's getModuleConfigInputfields function: public static function getModuleConfigInputfields(array $data) { $inputfields = new InputfieldWrapper(); $name = 'my_page_select'; if(!isset($data[$name])) $data[$name] = 0; $f = wire('modules')->get('InputfieldPageListSelect'); $f->attr('name', $name); $f->attr('value', $data[$name]); $inputfields->add($f); return $inputfields; } 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