Jump to content

Recommended Posts

Hi folks!

 

I've read the posting guidelines, and this should probably be posted in "Newbie Help", but I couldn't seem to find that forum. If this is in the wrong place, my apologies and could a moderator move it for me please?

 

 

I (or more accurately, my client) want to load the current page in a new (popup) window styled with the printer friendly style sheet. I've tried a couple of different methods, so far without success.

 

First I tried the method described here: http://www.maratz.com/blog/archives/2004/09/21/10-minutes-to-printer-friendly-page/

 

I'm not exactly sure where this went wrong, but seemed to apply BOTH styles, which hid much of the page (as per printer friendly version) even when the parameter for the printer version wasn't appended to the url.

 

Then I tried this method: http://inobscuro.com/tutorials/read/27/

 

This one seemed to cause a php error. The page was tendered without any style, and the last 4 characters of the php were drawn at the top of the page: ';?>

 

Any suggestions? The site is built using MODxCMS and is generated dynamicaly from templates, and output as a php file. Could my problem be due to the page already being the output of a php file?

 

Php replacing the usual style sheet call in the usual place:

<?php
    if($style == 'printFriendly') $stylesheet = 'assets/css/hjprint.css';
        else $stylesheet = 'assets/css/hjmain.css';
    echo '<link rel="Stylesheet" href="'. $stylesheet .'" type="text/css" />';
?>

The link to the printer friendly page:

<a href="[~[*id*]~]&style=printFriendly" target="top" title="Print View"><img src="images/menubutt3.gif" width="32" height="26" alt="Print" border="0" oversrc="images/menubutt3-on.gif" /></a>

The HTML code output containing the php script (obviously not working as this should just look like a normal style sheet call):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Harry Jenkins MP</title>
<script src="http://www.orionvisuals.com/wip/harryjenkins/styleswitcher.js" type="text/javascript" language="Javascript"></script>
<?php
    if($style == 'printFriendly') $stylesheet = 'assets/css/hjprint.css';
        else $stylesheet = 'assets/css/hjmain.css';
    echo '<link rel="Stylesheet" href="'. $stylesheet .'" type="text/css" />';
?>
<link id="iecss" rel="stylesheet" href="assets/css/hjie.css" type="text/css">
...etc

Link to the page as it is at the time of this post with the erroneous output:

http://www.orionvisuals.com/wip/harryjenkins/

 

Thank you in advance for any help you are able to offer!

 

I've been experimenting with the php to try and narrow down the problem. I've made the following test page: http://www.orionvisuals.com/wip/harryjenkins/phptest.php

 

The file has the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Harry Jenkins MP</title>
<script src="http://www.orionvisuals.com/wip/harryjenkins/styleswitcher.js" type="text/javascript" language="Javascript"></script>
<?php
if($style == 'printFriendly') $stylesheet = 'assets/css/hjprint.css';
	else $stylesheet = 'assets/css/hjmain.css';
echo '<link rel="Stylesheet" href="'. $stylesheet .'" type="text/css" />';
?>

<body>

<p>testing</p>

<p><a href="?style=printFriendly">Print view</a></p>

<div id="printhide"><p>Should be hidden in printer view</p></div>

</body>
</html>

 

I'm not having a problem in this example with the php failing to replace the style sheet. When looking at the generated code, there's no php to be seen, only a style sheet link in its place. However the swapping isn't working. If you click on the link in the page, and then look at the new page's source, you will see it's using the default css - hjmain.css - not the printer version - hjprint.css -. If I reverse the two in the php and put the main css in the line "if($style == 'printFriendly') $stylesheet = '  then the printer version of the style is loaded, and when the link clicked - it stays the same. It seems that the SECOND style sheet referenced in the php is used, regardless of the arguments appended to the url linking to it.

 

So this doesn't shed any light on why the php isn't working on the main site, but adds another new problem into the mix! This is getting frustrating...

I couldn't find a link to edit my post so I'm afraid I'll have to make a reply and bump the thread. My apologies if this is considered spamming.

 

It was suggested to me that it might be a register globals problem, and I should use this code:

 

if($_GET['style'] == 'printFriendly')

 

That's a step forward! The test file I made is now working:

http://www.orionvisuals.com/wip/harryjenkins/phptest.php

 

However the version on the live site is still showing the same problem where the php code doesn't seem to be executing, but it being parsed as-is to the html file.

 

It's just occurred to me that i mught need to use some special MODx code to insert php directly into a template, so I'll go look at that.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.