Re: [Phphtmllib-devel] howdy
Status: Beta
Brought to you by:
hemna
|
From: Walter A. B. I. <wab...@bu...> - 2002-06-05 05:24:07
|
> Along the widget lines, I would like to see the idea of themes
> implemented in PhpHtmlLib. I really like the the idea of themes
> that PHPnuke, PostNuke, et al. offer but I don't want or need their
> idea of users, articles, surveys, ad naseum. I just want flexible,
> easy to use themes.
---There is some form of widget theming built in to the BaseWidget
class. I kinda threw it together one night as a hack, so I know its not
perfect, but it works for the most part.
How it works is this. Any widget that you want to be "themable", it
has to have a css file, which is a .php file. The .php file contains
mostly all css definitions. Take a look at
phphtmllib/widgets/css/TextNav.php. It's a simple example.
What you do is to just make the values of the css items you want to be
changeable on the fly into php variables. So for example, in
widgets/css/TextNav.php, you will see
A.textnavlist:hover {
color: $fonthover;
}
where the value for the color is a php global var.
In widgets/TextNav.inc you will see a member variable called
$_css_colors, which is an array of name=>value pairs. The name should
be the name of the var you use in the css php file.
You will also see the $_css_file var which is the name of the css file
that is used for the widget.
What the hell is this crap? :)
Well, there is a method in the BaseWidget class called get_css_file().
This method returns a string which is the path to the css file used by
the widget, along with a query string of the name=value pairs of the
themed items. So at some point in a script when u create the particular
widget, you add the css link to the page, and it will automatically
create the link to the php css file with the name=value pairs in the
query string, which will set the values of the global variables in the
php css file. Its a hacked way of dynamic theming. You can manage the
values of the $_css_colors array with the methods:
set_css_item_color( $name, $value ) and
get_css_item_color( $name )
So if you want to use this, when u create a widget, all you have to do
is build the css file as php, and add the $_css_file member variable, as
well as the $_css_colors array with the names, and default values.
example?
<?php
$page = new HTMLPageClass("some lame name");
$textnav = new TextNav(400);
//you can change the themed values here BEFORE
//you add the css link to the page.
//uncomment these next 3 lines to override
//the default themed colors for the widget.
//$textnav->css_set_item_color("background", "#CC0000");
//$textnav->css_set_item_color("font", "#00FF00");
//$textnav->css_set_item_color("fonthover", "#FFFFFF");
//add the css link to the page w/ the themed values
$page->push_css_link( $textnav->get_css_file() );
$textnav->push("http://www.amazon.com", "Amazon", 200 );
$textnav->push("http://www.ebay.com", "Ebay", 200 );
$page->push( $textnav );
print $page->render();
?>
I hope this made SOME sense at least. I know its not a perfect
solution, but it worked for me at the time I needed it. I'd like
a more flexible and elegant solution if possible, but this does work.
Walt
|