twols Posted April 20, 2016 Share Posted April 20, 2016 Hello guys! Is it possible to render a template depending on the URL? The "normal" page by using the html-Template and with the ".xml" extension a different template? I would write a module or something, but may be there is smarter way for solving my problem Link to comment Share on other sites More sharing options...
DaveP Posted April 20, 2016 Share Posted April 20, 2016 I think PW has you covered there, There's a Content-Type select on the Files tab for each template. The note underneath says 'To add more content types see contentTypes in /wire/config.php (and add them in /site/config.php).'. 2 Link to comment Share on other sites More sharing options...
twols Posted April 20, 2016 Author Share Posted April 20, 2016 Thank you, @DaveP, but the "standard" way of PW is allowing only one mime type per template. I want to represent the same listing of posts in html or xml format. But may be I should simply create two templates and two pages. Though it is not that clean and creates additional content used only for structuring formats. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 20, 2016 Share Posted April 20, 2016 File extentions in the url are parsed as part of the page name. So you either need two different pages anyway or you need to handle everything on the parent page's template and use urlSegments. Alternatively you could also hook into the initial request parsing and implement your own "file type" routing logic. Link to comment Share on other sites More sharing options...
Noel Boss Posted October 1, 2019 Share Posted October 1, 2019 You can just change $page->template->contentType and $page->template->altFilename at runtime… $html = $page->render(); $page->template->contentType = 'txt'; $page->template->altFilename = "Mail.txt.php"; $txt = $page->render(); $count = $this->mail->new() ->subject($subject) ->body($txt) ->bodyHTML($html) ->send(); For me, altFilename actually is enough… 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