Jump to content


Photo

setting equal variables


  • Please log in to reply
2 replies to this topic

#1 hcspider

hcspider
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 August 2006 - 09:39 PM

I'm fairly new to PHP. I've used it for basic includes and that's about the extent of my experience, so please excuse me if this is a pretty obvious answer.

I'm building a site now where I define certain variables in the top of the page (title, pageID, pageClass... things of that nature). Something like this:

<?php 
	$pageTitle = "Welcome!"; //set page title
	$pageID = "home"; //top level category of page
	$pageClass = "threecolumncenter"; //layout of page
?>
...
<body id="<? echo $pageID; ?>" class="<? echo $pageClass; ?>">

I'm also using the class in the body tag as a way to define the layout of the page (2 columns, 3 columns, 4 columns, etc) using CSS. It's working great. But now, there will be more than just me editing this site so I'd like a way to uncomplicate the CSS class names since they are long and could easily cause typos.

To do this, ideally I'd like to use a PHP script that could read something like:

<? if ($layout == "3center") set $pageClass == "threecolumncenter"; ?>

This way, $layout would be defined at the top of the page like the other variables.

I know there's no "set" function, but how could I go about doing this? I've tried everything I could think of, and Googleing but I'm afraid my naivety in how to define this is stopping me from finding an answer.

Is this making sense? Thanks...

Addam

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 August 2006 - 09:41 PM

The same way you are setting up your other variables.
<?php
if ($layout == "3center")
{
    $pageClass = "threecolumncenter";
}
?>


#3 hcspider

hcspider
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 August 2006 - 09:49 PM

that's perfect. thanks wildteen... sometimes, it's so obvious you miss it. ugh... thanks so much




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users