Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-03-01 17:42:56

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Extending Themes

I routinely hack Hive (which I love) but doing so makes svn updates messier and I have to manually merge in differences…

IDEA: New Advanced Preference
additional theme css [/path/to/my/extra.css]
I’d love an advanced preference that would take a path to an additional css file that gets loaded after the theme. That way you stay stock (or 3rd party stock) AND you can extend a theme with your own tweeks.

Offline

#2 2013-03-01 19:19:47

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 329
Website

Re: Extending Themes

+1. That would be excellent.

Offline

#3 2013-03-01 20:51:54

shayne
Member
From: Toronto
Registered: 2005-02-22
Posts: 34
Website

Re: Extending Themes

+1. Awesome Idea!

Offline

#4 2013-03-02 10:59:43

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: Extending Themes

I think you can create your own theme based on Hive, which will just add your CSS.

But yes, a preference is a little less geek, but this style sheet will apply to all the themes?

Offline

#5 2013-03-02 22:21:36

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Extending Themes

In my opinion, this would suit better a plugin. While it’s not a bad idea, it doesn’t make sense in terms of usability or what the preference panel should offer. But it’s a wonderful idea for a plugin. An actual theme extending is an existing feature.

As noted by sacripant, if you want to extend a theme, you can. You can base a theme to another using just standard PHP features. E.g.

/**
 * Tells Textpattern to which theme is required by the theme.
 * This basically loads the other theme on the background.
 */

theme::based_on('hive');

/**
 * Extends Hive theme.
 *
 * This theme would be named after the class as a 'abc_extends'. The directory
 * structure is constructed like any other admin-side theme.
 */

class abc_extends_theme extends hive_theme
{
	/**
	 * Overrides the theme properties to Hive's.
	 *
	 * This makes sure the resources link to Hive theme
	 * and not to this bare mirror.
	 */

	public function __construct()
	{
		parent::__construct('hive');
	}

	/**
	 * Adds an extra CSS file to the head.
	 */

	public function html_head()
	{
		return 
			parent::html_head().
			n.'<link rel="stylesheet" href="'.THEME.'/abc_extends/css/my_extra.css">';
	}
}

Or something like that. I haven’t tested the code, but the extending works like that. It’s simple, yet powerful. In other words, adding a single CSS file to a theme doesn’t take more than a single PHP file with few lines in it. You have a your own new theme you can modify that uses an existing theme as a base.

Last edited by Gocom (2013-03-02 22:25:29)

Offline

#6 2013-03-03 00:42:18

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,081
Website

Re: Extending Themes

@Gocom

Can’t Hive be extended the same way Remora extends Classic?

The new theme can then just link to own stylesheets, js, and fill in a couple of functions (header, footer). I use Classic as a base for Sandspace that way. I haven’t tried doing it with Hive.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#7 2013-03-03 07:00:39

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Extending Themes

phiw13 wrote:

Can’t Hive be extended the same way Remora extends Classic?

Yes of course. That’s practice is ideally the same, you are just overloading different methods, and having to provide different things. It’s the same extending. The cool thing is, if you don’t want to change any of the methods, you don’t have to. You will not have to manually link any resources or fix the theme when the parent is updated. You can basically even just clone the other theme under a different name.

For instance the above creates a theme that is identical to Hive, with the slight expectation that it adds a single CSS file to the head. Outside of that slight difference, it links to all the resources used and provided by Hive and is updated with the theme too. You don’t have to provide any of the resources (CSS, JS) used by Hive with the theme, nothing. It will basically almost never get out dated or break. It’s a theme that consists of one PHP file, and the extra CSS file.

That said, you may want to at least provide it different name for it. Which you can do after setting the theme’s properties to Hive. The name is carried in the $name property.

parent::__construct('hive');
$this->name = 'abc_extending';

Not that name is even really used. The only place where it is used, is the dropdown on Preferences panel. It provides the label for the theme for that single input.

The properties are set to the parent’s, Hive’s, due to linked resources. If that wasn’t done, the resources would link to the current’s themes sub directory where they are not. By setting the properties to Hive’s, the resources will correctly be loaded from Hive, instead of the new theme.

I use Classic as a base for Sandspace that way.

Yep, that is a one correct way of extending of a theme. Speaking of Sandspace, while looking at its code I saw;

$prefs = get_prefs();

That loads the whole preference table from the database. Try get_pref() instead, or the global $prefs array — but I would recommend the documented get_pref(). That get_prefs() isn’t good for you. Only Textpattern itself should be using it, and even it can call it just once.

I haven’t tried doing it with Hive.

You can do the same stuff with any theme, of course depending on what the theme does in its class. Not all themes are necessarily well made or extendable.

Last edited by Gocom (2013-03-03 07:15:39)

Offline

#8 2013-03-03 10:19:53

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: Extending Themes

Try this skeleton child theme for Hive as a start.

Offline

#9 2013-03-03 11:55:39

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,081
Website

Re: Extending Themes

Gocom wrote:

… Yep, that is a one correct way of extending of a theme. Speaking of Sandspace, while looking at its code I saw … $prefs = get_prefs();

hmm. I don’t remember exactly why it is there (has been there for a long long time) – I think something with fetching site-name ? I’ll have to dive into my archives. Any way, I removed it and changed the way the h1 with site link is generated. Thanks for flagging that one.

Wet wrote

Try this skeleton child theme for Hive as a start.

Nice simple way to customise a theme.

BTW – Did you know that the ‘help link’ in the core themes’ manifest (this page) returns a 404.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#10 2013-03-03 16:01:06

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Extending Themes

Thanks Wet and Jukka…

I forgot all about the mechanism to extend themes. Been custom hacking Sandspace and now Hive the messy way for years.

What can I say… I’m not a smart man.

Offline

#11 2013-03-05 17:28:43

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: Extending Themes

This page in the docs has always existed, via the Themes section of the main page, though I did just tidy it up a bit….

Creating and using admin-side themes

One question, though… it talks about adding a “screenshot.ext” file for visual selection of admin-themes. Is that added to the root “..theme/” directory, or to the directory of the specific theme (../theme/foo_theme/)?

Offline

#12 2013-03-05 18:40:58

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Extending Themes

Destry wrote:

One question, though… it talks about adding a “screenshot.ext” file for visual selection of admin-themes. Is that added to the root “..theme/” directory, or to the directory of the specific theme (../theme/foo_theme/)?

To the theme’s own directory (e.g. ./theme/foo_theme/). Wouldn’t do much good in the parent directory, other than prevent having theme specific screenshots.

Offline

Board footer

Powered by FluxBB