Page 1 of 1

Link parameter to set different template?

Posted: Tue Dec 14, 2010 4:40 pm
by appleyard
Hi there,

I'm trying to set up a "print page" link on my site, and the {print} tag will not work for me for several reasons. (I use Textile formatting in my main content block, there are additional custom content blocks, etc.)

It seems like the easiest thing to do would be to create a template that strips out the menu and other elements, but lets me style the other things how I want, and use {cms_selflink} to link to that using some parameter that forces the specific template. But for the life of me I can't find anything in the documentation that shows how to do that. Can anyone help? Thanks!

Re: Link parameter to set different template?

Posted: Mon Dec 20, 2010 11:35 am
by tomgsd
You could use an additional get variable in the url and then use smarty to vary the output in your main template.  For example:

Code: Select all

www.yoursite.co.uk/page?printable=true
Then in the template:

Code: Select all

{if $smarty.get.printable}
    print only stuff
{else}
    normal stuff
{/if}
Hope this helps!

Re: Link parameter to set different template?

Posted: Wed Dec 22, 2010 2:48 pm
by appleyard
Thanks, I'll try that!

However, I'm still curious: is there not a way to serve content in a different template based on the results of an {if} statement or Javascript check? That would be helpful for my printing issue, but also for serving a touch-optimized site to mobile devices, etc.

Re: Link parameter to set different template?

Posted: Wed Dec 22, 2010 3:16 pm
by tomgsd
As far as I'm aware it's not possible.  However, there are other means like alternative stylesheets (using media="print, handheld, etc").

Also, you could create multiple content blocks in your template ({content block="block1, block2, etc"}) and show different content that way.  I always use the AdvancedContent module to do this sort of thing because it gives tons more options on the editing side - you can even use things like checkboxes which are a great feature.

More recently, I've managed to create some sites with a single template and then allow users to turn on/off sideboxes or switch layouts when editing the content.  I don't think it would be too difficult to have a UDT to detect a mobile browser and serve up different content in a similar way.