Using a single page for print styles

Permalink
Hi there,
Ive been trying to figure out if this is possible and im sure it is, but would anyone be able to point me in the right direction for using a single page as a 'print page'?

Basically we have a client with a bunch of recipes on their site. And due to the layout creating a print.css is beyond a nightmare.

So i had a thought of incorporating a print button, which then gathers all the content we want to print, loads this into a single page with minimal styling that can then be printed...

I have seen a few blocks out there for printing (tested, and none do this..), but is there a way to get the contents of particular areas and then pass that to a single page?

Any help would be most appreciated!

Many thanks!

jpcharrier
 
hutman replied on at Permalink Reply
hutman
I think you should be able to do this by passing the cID of the page in to your Single Page controller. Then you can do something like this to get the blocks from which ever areas of the page you want

$page = Page::getByID($cID);
$blocks = $page->getBlocks($areaName);
foreach ($blocks as $b) {
   $b->display();
}
jpcharrier replied on at Permalink Reply
jpcharrier
Thanks... Although I'm still a little confused.

What Im trying to do is have a print button, that opens a new window that shows certain areas from the original page unstyled (so that i can use that to print from with its own print styles).

We are trying to do this instead of having to generate a huge print.css file which overrides/strips our styling down to then print from (which would be a mammoth task).

SO im taking this opportunity to get my head around linking to a new page and passing the original page's ID etc so that data can be accessed/formatted etc...

Is that something I can do with single pages or is that more package level or...?

If anyone could post some sample code as to how you would link to a single page and pass a variable such as the cID, that would be amazing!
mnakalay replied on at Permalink Reply
mnakalay
I know you're looking at another way of doing it but I don't understand what you find so daunting about the print.css option.
Whatever style you would create for the "print page" you want would be your print.css and for everything you don't want printed you just set a display:none in the print.css.
mesuva replied on at Permalink Reply
mesuva
Here's my suggestion.

Page types normally have an element at their top:
$this->inc('elements/header.php');
Therefore, you can if you need dynamically change what header file gets included. So perhaps you could use a GET parameter to change the header element over to a stripped down one with one print stylesheets, e.g.:

<?php if ($_GET['print'] == '1') { 
    $this->inc('elements/header_print.php'); 
} else {
   $this->inc('elements/header.php'); 
} 
?>


Then in your header_print.php file, you'd NOT include your main stylesheet, only the stuff you need for printing. You can use this approach to create a very stripped down very of a page, where you could for example remove all of your navigation areas and stylesheets, just leaving the actual page content. You might also need to do the same on the footer to avoid adding closing tags you don't need.

Then if your page type is responding to a GET parameter, for a print link it's just a matter creating a link to the current page, add in the parameter (maybe opening in a new window).

I've sort of talked about this approach in an old blog post:
http://www.mesuva.com.au/blog/concrete5/adding-ajax-source-pages-in...
Looks at steps 1 and 2. Steps 3 and beyond aren't really relevant. In this example I created a separate page type with the stripped down header and footer elements, I'm just suggesting you could do this dynamically, all in the page type file for your recipe.

Hope that makes sense
-Ryan