Jump to content

Setting different MIME-Types for a template


twols
 Share

Recommended Posts

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

I think PW has you covered there,

post-378-0-47608800-1461151833_thumb.png

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).'.

  • Like 2
Link to comment
Share on other sites

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

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

  • 3 years later...

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…

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...