[SOLVED]How to print out individual content blocks

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

[SOLVED]How to print out individual content blocks

Post by blackhawk »

Is there a way to print any given content block on a page? For example if I have 4 content blocks on a page, and have a print button next to each one, clicking on any given print button will print the associated content block?

Thanks
Last edited by blackhawk on Mon Apr 22, 2013 1:35 am, edited 1 time in total.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: How to print out individual content blocks

Post by blackhawk »

Anyway to do it with global content blocks?
gocreative
Power Poster
Power Poster
Posts: 265
Joined: Mon Mar 14, 2011 1:16 am

Re: How to print out individual content blocks

Post by gocreative »

Wrap each content block in a DIV with a unique ID. For example:

Code: Select all

<div id="content-block-1">
{content}
</div>
Repeat for all other content blocks, obviously changing the number from '1' to 2, 3, 4 etc.

Then use Javascript to grab the contents of just that DIV, using the element's ID, and print it. Example:

Code: Select all

<__html>
<head>
<__script__ type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" > </__script> 
<__script__ type="text/javascript">

    function PrintElem(elem) {
        Popup($(elem).text());
    }

    function Popup(data) {
        var mywindow = window.open('', 'my div', 'height=400,width=600');
        mywindow.document.write('<__html><head><title>my div</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head></__body >');
        mywindow.document.write(data);
        mywindow.document.write('<__body></__html>');
        mywindow.document.close();
        mywindow.print();
        return true;
    }

</__script>
</head>
</__body>

<div id="content-block-1">
{content}
</div>

<input type="button" value="Print Content Block 1" onclick="PrintElem('#content-block-1')" />

<a href="javascript:void(0)" onclick="PrintElem('#content-block-1')" />Another way to call the print dialog</a>

<__body>
</__html>
Note: Untested.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: How to print out individual content blocks

Post by blackhawk »

Thank you very much for this creative idea!
gocreative
Power Poster
Power Poster
Posts: 265
Joined: Mon Mar 14, 2011 1:16 am

Re: [SOLVED]How to print out individual content blocks

Post by gocreative »

Glad I could help!
Post Reply

Return to “CMSMS Core”