Jump to content

Recommended Posts

Posted

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 :)

Posted

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
Posted

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.

Posted

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.

  • 3 years later...
Posted

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

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
  • Recently Browsing   0 members

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