SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

Using a Print Stylesheet

Often people want to be able to print webpages without all the menus and graphics and with all the content fitting correctly onto a page. To do this you need to create a separate print stylesheet. It would look something like this:

All you need to do to include a Print stylesheet in your page is to run a seperate Requirements call and specify that it is for print within the init() function of your Page_controller.



Then you just need to add some print styles to Print.css, something like this:


#footer {
	display: none;
	width: 100%; 
	margin: 0; 
	float: none;



Aram Balakjian avatar

Aram Balakjian

Aram is a web developer running London based agency Aab Web. He has a strong passion for developing attractive, usable sites around the SilverStripe CMS.

  • MRKDevelopment
    21/11/2010 11:22am (7 years ago)

    One thing I don't like about this is it isn't in the theme.

    This is far from Ideal because all code to do with views should be separate in a strict sense as you want to be able to switch out themes without having to adjust controller code.

    If you include css in the way suggested you would have to re write a lot PHP code if you choose to change theme.

  • ian holmes
    12/01/2011 12:27pm (6 years ago)

    You can have both the screen and print media styles in the same css sheet - just use:

    @media screen {



    @media print {


    This means less code to change and only one http call to download one css file for the whole site.

  • Pete Bacon Darwin
    12/05/2011 1:44pm (6 years ago)

    I have found that I can achieve the requirement inside the template by adding the extra parameter in the template command:

    <% require themedCSS(print, print) %>

    This lives in the theme's template .ss file. The first parameter refers to the name of the css file stored in the theme's css folder. The second parameter is the media format, in this case "print".

Post a comment ...

You cannot post comments until you have logged in. Login Here.


Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image wfacewomens
3 article image Daniel Hensby
4 article image Marcus Dalgren
5 article image ryduhartchas
6 article image Hamish Campbell
7 article image Ty Barho
8 article image Martijn van Nieuwenhoven
9 article image Darren-Lee
10 article image Roman Schmid

View full leaderboard