Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-26 22:18:39

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

PHP Stylesheet Switcher

Hello all, and please forgive my newbie-ness.

Just installed TXP this morning, and am working on converting my old MovableType site over. I’ve got a piece of PHP code I wrote to automatically switch stylesheets. Here’s the code:

<?php
$month = date(n);
$day = date(j);
include("/home/myspace/public_html/styles/stylebydate.php");
$sheet = styles($month, $day);
?>
<link rel="stylesheet" href="http://www.mysite.com/styles/basic.css" type="text/css" />
<link rel="stylesheet" href="http://www.mysite.com/styles/<?php print $sheet; ?>.css" type="text/css" />

The “stylebydate” function takes the date then assigns the appropriate stylesheet name to the variable $sheet. Then the two stylesheets are assigned. The “basic.css’ sheet is all framework; the variable sheet is colors and artwork. This way, I can show a different style depending on the date – happy birthday to me, seasonal greetings, whatever – without having to manually change the sheet.

I’m trying to convert this to TXP. I get this far:

<txp:php>
$month = date(n);
$day = date(j);
include("stylebydate.php");
$sheet = styles($month, $day);
</txp:php>
<txp:css format="link" n="basic" />
<txp:css format="link" n="<txp:php>print $sheet;</txp:php>" /> 

What I get in the source code using that is this:

<link rel="stylesheet" type="text/css" media="screen" href="http://www.afterhourspub.com/textpattern/css.php?n=basic" />
<link rel="stylesheet" type="text/css" media="screen" href="http://www.afterhourspub.com/textpattern/css.php?n=" /> 

The problem is I can’t make it hold that variable within TXP. I tested the straight php code here and it returns the variable for $sheet, but I can’t make it do that from within TXP. I’ve tried this:

<txp:php>
$month = date(n);
$day = date(j);
include("stylebydate.php");
$sheet = styles($month, $day);
print "The variable assigned is ".$sheet;</txp:php>

But it just comes up “The variable assigned is: “ and nothing after that.

Any help you can give is greatly appreciated!

-Iki


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

#2 2008-05-27 00:44:39

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Re: PHP Stylesheet Switcher

Whew… a few more hours of alternately poring over stuff like this and this and I found it.

<txp:php>
include("stylebydate.php");
global $sheet;
$month = date('n');
$day = date('j');
$sheet = styles($month, $day);
</txp:php>
<txp:css format="link" n="basic" />
<txp:css format="link" n="<txp:php>global $sheet; print $sheet;</txp:php>" /> 

Sometimes just seeing the problem in print helps. :)


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

Board footer

Powered by FluxBB