Page 1 of 1

[SOLVED]How to print out individual content blocks

Posted: Wed Apr 04, 2012 4:50 pm
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

Re: How to print out individual content blocks

Posted: Thu Apr 05, 2012 12:26 pm
by blackhawk
Anyway to do it with global content blocks?

Re: How to print out individual content blocks

Posted: Mon Apr 23, 2012 3:44 am
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.

Re: How to print out individual content blocks

Posted: Mon Apr 22, 2013 1:35 am
by blackhawk
Thank you very much for this creative idea!

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

Posted: Mon Apr 22, 2013 1:55 am
by gocreative
Glad I could help!