Hi everyone,
has anybody customised the print tag function in CMSMS to include additional content blocks?
What i am trying to achieve is a printable version of the whole 'content' div, not just the {content} tag.
Or: I am sure this would also be possible opening the displayed page in a new window and using some CSS to hide the unwanted divs (display:none;), but I wouldn't know how to implement that either.
Any help is greatly appreciated,
Seb
Customising print tag to include additional content blocks
Re: Customising print tag to include additional content blocks
IIRC we did something like that for 1.0betas 
-
websherpa
Re: Customising print tag to include additional content blocks
I'd like to open this one up again to see if someone can help here. That is exactly where we're at too, either wanting to modify the print funciton function.print.php to print out ALL of the contents within a range (not just the main {content} tag) since we have added important content blocks to the page outside this area.
We'd also like to add important things like {title} and perhaps some other custom bits.
Or go the other root which is to respawn the window and have unwanted Divs not displayed for printing (which is the classic method).
But without spending time decoding, I need some help getting a handle on how the print function currently works, and how to approach accomplishing what we want to do above.
Does the function.print.php (Version 1.0) page handle just the creation of the Print Button? Is the actual print page and javascript to spawn a print dialogue handled elswhere in the code? (If so, where please.)
Thank you for your help!
We'd also like to add important things like {title} and perhaps some other custom bits.
Or go the other root which is to respawn the window and have unwanted Divs not displayed for printing (which is the classic method).
But without spending time decoding, I need some help getting a handle on how the print function currently works, and how to approach accomplishing what we want to do above.
Does the function.print.php (Version 1.0) page handle just the creation of the Print Button? Is the actual print page and javascript to spawn a print dialogue handled elswhere in the code? (If so, where please.)
Thank you for your help!
Re: Customising print tag to include additional content blocks
I would do it with custom print css.
css is the way to go when changing layout.
css is the way to go when changing layout.
-
websherpa
Re: Customising print tag to include additional content blocks
Thank you. Well yes, but (and I am not a hard core coder, but sometimes I can intuit how these things work) by following the code back I found the library file (content.functions.php) that generates the print output page and it is set up to literally print only the {content} tag content:
Starts around line #387
So we still would have to modify the output manually (according to my template) so that it collects together all of the existing content blocks (and add Title, etc. - which I can do by hand by copying in code from the original page template to modify the above funciton;
or re-output the page, but attaches a specific "printing" css (but offhand I don't know how to do / integrate this);
or better yet, update the code for a future CMSMS version that dynamically addresses all of the content, including the blocks that don't have a 'noprint' parameter added to them, plus a separate print template is addressed which permits adding things like {title}, headers, layout etc.
Can anyone help out on programming this? I'd offer a fee (since i'm using this for a client, but we're over budget now, so it would have to be something quite reasonable)? However I think it would benefit all CMSMS users if not already contemplated.
Starts around line #387
Code: Select all
/* Print Page Function (I added this myself) */
else if (isset($_GET["print"]))
{
$script = '';
if (isset($_GET["js"]) and $_GET["js"] == 1)
$script = '<__script__ language="JavaScript">window.print();</__script>';
if (isset($_GET["goback"]) and $_GET["goback"] == 0)
{
$tpl_source = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'<__html><head><title>{title}</title><meta name="robots" content="noindex"></meta>{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body style="background-color: white; color: black; background-image: none; text-align: left;">{content} Hi there!'.$script.'<__body></__html>';
}
else
{
$hm =& $gCms->GetHierarchyManager();
if (true == $config['assume_mod_rewrite'])
{
$curnode =& $hm->getNodeByAlias($tpl_name);
}
else
{
$curnode =& $hm->getNodeById($tpl_name);
}
$curcontent =& $curnode->GetContent();
$page_url = $curcontent->GetURL();
$tpl_source = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'<__html><head><title>{title}</title><meta name="robots" content="noindex"></meta>{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body style="background-color: white; color: black; background-image: none; text-align: left;"><p><a id="back" href="'.$page_url.'">« Go Back</a></p>{content}'.$script.'<__body></__html>';
}
return true;or re-output the page, but attaches a specific "printing" css (but offhand I don't know how to do / integrate this);
or better yet, update the code for a future CMSMS version that dynamically addresses all of the content, including the blocks that don't have a 'noprint' parameter added to them, plus a separate print template is addressed which permits adding things like {title}, headers, layout etc.
Can anyone help out on programming this? I'd offer a fee (since i'm using this for a client, but we're over budget now, so it would have to be something quite reasonable)? However I think it would benefit all CMSMS users if not already contemplated.
-
websherpa
Re: Customising print tag to include additional content blocks
A simpler modification that would do for now would be for me to ask, how can I change this:
So it returns the current page in a different (specifically hard coded) template than the one assigned to the Page itself (or better yet looks for a template that is based on the original page's alias/name plus '_print' (thus a specific print css could be assigned to each customized print template - if required).
Or am I overthinking this thing?
Code: Select all
$tpl_source =
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'
<__html>
<head><title>{title}</title><meta name="robots" content="noindex"></meta>{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body style="background-color: white; color: black; background-image: none; text-align: left;">{content} Hi there!'.$script.'<__body>
</__html>';
Or am I overthinking this thing?
Last edited by websherpa on Mon Nov 27, 2006 9:55 pm, edited 1 time in total.
Re: Customising print tag to include additional content blocks
From what I see the print page function has a hardcoded template that pulls in the stylesheets in use and the content block.
Soapbox: separate the functionality form the layout/presentation. Also the hardcoded template has style declarations in the body. I'm glad I found that because I've be trying to style my "Print" CSS for several days and couldn't see why my styles were not being recognized... anyway, I should have looked at the source earlier.
So, my crappy solution is to pull in global content blocks.
The great thing about CMS MS is global content blocks. I use them for my header and footer among other things so my footer isn't a separate file being included in the template that is out side of the templating system. I realize that may not be clear...
So, because I'm using global content blocks for the header and footer, I can add that into the content.functions.php file. I don't like this solution because it hack the core files...
What I did was this - as mentioned begining at line 387, look for $tpl_source around line 396:
and again around line 412:
I eliminated the inline css styles in the tag and add my smarty php tags for header and footer.
-John B.
Soapbox: separate the functionality form the layout/presentation. Also the hardcoded template has style declarations in the body. I'm glad I found that because I've be trying to style my "Print" CSS for several days and couldn't see why my styles were not being recognized... anyway, I should have looked at the source earlier.
So, my crappy solution is to pull in global content blocks.
The great thing about CMS MS is global content blocks. I use them for my header and footer among other things so my footer isn't a separate file being included in the template that is out side of the templating system. I realize that may not be clear...
So, because I'm using global content blocks for the header and footer, I can add that into the content.functions.php file. I don't like this solution because it hack the core files...
What I did was this - as mentioned begining at line 387, look for $tpl_source around line 396:
Code: Select all
$tpl_source = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'<__html><head><title>{title}</title><meta name="robots" content="noindex">{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body>{global_content name="header"}<br>{content}<br>{global_content name="footer"}'.$script.'<__body></__html>';
Code: Select all
$tpl_source = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'."\n".'<__html><head><title>{title}</title><meta name="robots" content="noindex">{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head></__body><p><a id="back" href="'.$page_url.'">« Go Back</a></p>{global_content name="header"}<br>{content}<br>{global_content name="footer"}'.$script.'<__body></__html>';
I eliminated the inline css styles in the tag and add my smarty php tags for header and footer.
-John B.
Last edited by JohnnyB on Sat Dec 16, 2006 12:03 am, edited 1 time in total.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Re: Customising print tag to include additional content blocks
Update:
There is something else controlling the output of the print tag because I still can't see my style rules in my "print" css template. Or, using the print tag, the template stylesheets are not regarded.
As a test, If I put
* {display:none}
I can still see the header and content....
But, using the print functionality of my browser (Ffox), I see a blank page...
Ugh.
I may just use a php or JS print button that triggers the default browser output....
EDIT: I'm now using in my page content and relying on my stylesheet template.

There is something else controlling the output of the print tag because I still can't see my style rules in my "print" css template. Or, using the print tag, the template stylesheets are not regarded.
As a test, If I put
* {display:none}
I can still see the header and content....
But, using the print functionality of my browser (Ffox), I see a blank page...
Ugh.
I may just use a php or JS print button that triggers the default browser output....
EDIT: I'm now using in my page content and relying on my stylesheet template.
Last edited by JohnnyB on Sat Dec 16, 2006 1:21 am, edited 1 time in total.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
-
Steppenwolf
- Forum Members

- Posts: 19
- Joined: Fri Dec 01, 2006 11:22 am
Re: Customising print tag to include additional content blocks
Thank you John for this quite simple solution!
Because I always take care for non javascript users, I built a switch, so they get the standard {print}:
Because I always take care for non javascript users, I built a switch, so they get the standard {print}:
Regards Eberhard
{print showbutton=true text='Print page' popup=true}
document.getElementById('PrintWithJS').style.display = 'inline';
document.getElementById('PrintWithoutJS').style.display = 'none';

