Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Multiple Templates for a Single Page

Go to End

4 Posts   2349 Views

Ben Gribaudo

Community Member, 181 Posts

18 June 2009 at 2:02am


What would be the best way to have two templates for a single page? Practical use would be an e-mail newsletter archive where the public views the newsletters using one template and where the alternative template is used by an e-mail sending service when it pulls the newsletter to send it. The alternative template should be accessible by appending a query string to the page's URL.

One idea on how to do this: in the newsletter page's controller, override something like handleAction() so that it changes the template used if the appropriate query string is present.

What do you think of this approach? Have another idea?



Community Member, 904 Posts

18 June 2009 at 2:23am

Hi Ben

That sounds about right. But AFAIK you don't have to override "handleAction".
Let's assume you got 2 use-cases: Browsing the newsletter on the website and creating a page version to be sent by your mailing service.
For the newsletter-browsing you would simply call the URL directly, i.e.:

To pull the "mail" version of the newsletter, you would call another URL, i.e.:

In your Newsletter_Controller you can then place a method called "mailable" that will be invoked when the latter URL is being called. There you would simply switch the template. Something like this:

public function mailable(){
	return $this->renderWith(array('mailable', $this->ClassName));

It would then render your newsletter with the "" Template.
I hope that was what you were looking for.

Ben Gribaudo

Community Member, 181 Posts

19 June 2009 at 6:27am

Thanks, Banal! Your tip helped us.



Community Member, 167 Posts

16 July 2009 at 6:38pm

Hmm, this could also work for, say, an iPhone (or generic mobile) version of a site, or would you do that differently?