Keyword

[SOLVED] Print View Override

  • Mr_Anonymous
  • Mr_Anonymous's Avatar Topic Author
  • Offline
  • Premium Member
More
10 years 5 months ago #133578 by Mr_Anonymous
[SOLVED] Print View Override was created by Mr_Anonymous
How do you override the print view? Is my only option is to edit the "components/com_k2/css/k2.print" file directly? I tried creating an override like "templates/mytemplate/html/com_k2/css/k2.print" and I dont think that works for print view. Can someone confirm this please...

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 5 months ago #133579 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Print View Override
It depends on the browser if it respects the print styles.
I personally add a new media query (@media print) in my template's stylesheet.

Please Log in or Create an account to join the conversation.

  • Mr_Anonymous
  • Mr_Anonymous's Avatar Topic Author
  • Offline
  • Premium Member
More
10 years 5 months ago #133580 by Mr_Anonymous
Replied by Mr_Anonymous on topic Re: Print View Override
Thanks. I ended up using another solution for this. I added the print check condition directly with php like this to hide the sections that I dont want to come up in printing:
Log in  or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 5 months ago #133581 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Print View Override
Yes this will also work.
Keep in mind that you might need a CSS solution as well, since Joomla!'s print button the browser's print button have a different result.

Please Log in or Create an account to join the conversation.

  • Mr_Anonymous
  • Mr_Anonymous's Avatar Topic Author
  • Offline
  • Premium Member
More
10 years 5 months ago #133582 by Mr_Anonymous
Replied by Mr_Anonymous on topic Re: Print View Override
Yeah you are right... When I printed the page as pdf I noticed the difference since the pop-up layout was different from actual printed layout. Thanks for pointing that out. :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 5 months ago #133583 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Print View Override
You 're welcome :)

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171091 by Sori
Replied by Sori on topic [SOLVED] Print View Override
Hi,

Would you please let me know which file is correspondent for the print view?
I want to make a very neat print view but right now everything is included in it like an article.

Thanks,
Sohrab

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171093 by Sori
Replied by Sori on topic Re: Print View Override
Hi,

How? can you provide an example please?

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171116 by JoomlaWorks
Replied by JoomlaWorks on topic Re: Print View Override
The print view is a combination of the component.php subtemplate (it should exist inside /templates/YOUR_TEMPLATE/), the K2 template overrides and some CSS (k2.print.css - see my other post on how to override it - www.joomlaworks.net/forum/k2-en/37337-how-do-i-override-the-k2-print-css#132612).

The file component.php acts as a wrapper for the K2 template files (item.php to be exact).

Examine this page for example: demo.getk2.org/item?tmpl=component&print=1 (although we don't use any specific print styling here).

You can event create an entirely different section for the print view in K2's item.php by having a big if/else statement there. Shouldn't be too difficult to see how to do that as it exists already in item.php, for example here: github.com/getk2/k2/blob/master/components/com_k2/templates/default/item.php#L15

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171262 by Sori
Replied by Sori on topic Re: Print View Override
I appreciate your reply.
I am studying them.

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171264 by Sori
Replied by Sori on topic Re: Print View Override
Ok . I studied them all. I didn't understand.
Would you please give me more direction like. A. do this.. B. do that...

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171265 by Sori
Replied by Sori on topic Re: Print View Override
the print layout for the joomla article is so neat and good. but for k2 is messy. but that's the only thing good about the joomla article system.

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171266 by Sori
Replied by Sori on topic Re: Print View Override
<?php if(JRequest::getInt('print')==1): ?>
<!-- Print button at the top of the print page only -->
<a class="itemPrintThisPage" rel="nofollow" href="#" onclick="window.print();return false;">
    <span><?php echo JText::_('K2_PRINT_THIS_PAGE'); ?></span>
</a>
<?php endif; ?>
The first line is for the button.
the second line to call for the print js action.
the third for the text.
How can I force it to open a custom php tempelate?
what should write? please guide me. I am not that adept in php but understand it.

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171267 by Sori
Replied by Sori on topic Re: Print View Override
Ok I also have this:
<?php if($this->item->params->get('itemPrintButton') && !JRequest::getInt('print')): ?>
			<!-- Print Button -->
			<li>
				<a class="itemPrintLink" rel="nofollow" href="<?php echo $this->item->printLink; ?>" onclick="window.open(this.href,'printWindow','width=900,height=600,location=no,menubar=no,media=no,resizable=yes,scrollbars=yes'); return false;">
					<span><?php echo JText::_('K2_PRINT'); ?></span>
				</a>
			</li>
			<?php endif; ?>

I understand it but what should I write in the place of printLink to open my designed template or where is printLink to edit?

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171274 by JoomlaWorks
Replied by JoomlaWorks on topic Re: Print View Override
This if statement at the top is shown only on the print page. Similarly, you can extend it to an if/else statement. Anything that is in the "else" part will only be shown when you are NOT on the print page/preview. Whatever is in the "if" part though will be shown only in the print page/preview. So in there you can add whatever you want from the rest of the PHP template variables you see in item.php. On 99,9% of the times, developers use some print CSS magic to spice up the print page. There is rarely a need to have different markup, that's why we chose this approach. Trust me, it's FAR more flexible than Joomla's...

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago - 6 years 2 months ago #171279 by Sori
Replied by Sori on topic Re: Print View Override
I trust you. K2 is the best. I don't have any joomla platform without it. It is essential. I understand it.
Ok I understood what you instructed. Very helpful.
Here I copy and paste what I did for my print layout so other like me won't get lost and can use this in no time:
<?php if(JRequest::getInt('print')==1): ?> 
<!-- Print button at the top of the print page only -->
<a class="itemPrintThisPage" rel="nofollow" href="#" onclick="window.print();return false;">
	<span><?php echo JText::_('K2_PRINT_THIS_PAGE'); ?></span>
</a>
<!-- 1 Item Title --> <h2 class="PrintTitle"><?php echo $this->item->title; ?></h2>
<!-- 2 Item Author -->	<span class="PrintAuthor">
		<?php echo K2HelperUtilities::writtenBy($this->item->author->profile->gender); ?>
		<?php if(empty($this->item->created_by_alias)): ?>
		<a rel="author" href="<?php echo $this->item->author->link; ?>"><?php echo $this->item->author->name; ?></a>
				<?php endif; ?>
<!-- 3 Item Image -->
	<span class="PrintImage">
	<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
	</span>
<!-- 4 Item introtext -->
		<div class="PrintIntroText">
			<?php echo $this->item->introtext; ?>
		</div>
<!-- 5 Item fulltext -->
		<div class="PrintFullText">
			<?php echo $this->item->fulltext; ?>
		</div>
		<?php else: ?>

<!-- End if moved to the very end of this page -->

<!-- Start K2 Item Layout -->

What you can not see here is that I moved the
<?php endif; ?>
to the very end of the item.php file. ALso as you can see I have defined new css classes.

Thanks
Last edit: 6 years 2 months ago by Sori.

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171280 by Sori
Replied by Sori on topic Re: Print View Override
The problem now is that the "Print this page" text is also shown in the printed documents.

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171281 by JoomlaWorks
Replied by JoomlaWorks on topic Re: Print View Override
It's this text obviously:
<a class="itemPrintThisPage" rel="nofollow" href="#" onclick="window.print();return false;">
	<span><?php echo JText::_('K2_PRINT_THIS_PAGE'); ?></span>
</a>

So you can either remove it entirely or simply move it elsewhere (e.g. at the bottom of the document).

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171284 by Sori
Replied by Sori on topic Re: Print View Override
No that didn't help.
I tried putting it everywhere. I still have it on the printed document.
On the original code that would go away on the printed document.

Please Log in or Create an account to join the conversation.

More
6 years 2 months ago #171285 by JoomlaWorks
Replied by JoomlaWorks on topic Re: Print View Override
That's because K2's print CSS makes that link hide upon printing: github.com/getk2/k2/blob/master/components/com_k2/css/k2.print.css#L10

You can keep the same class/markup as is or you can override k2.print.css by copying the file into /templates/YOUR_TEMPLATE/css/.

Please Log in or Create an account to join the conversation.