Category templates plugin with static pages

Creating and modifying plugins.
Post Reply
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Category templates plugin with static pages

Post by carl_galloway »

Can anyone tell me how to use this plugin?

Specifically what I want to do is assign a different template to certain static pages. I've allocated the templates in the categories admin screen, and in my static pages I've selected the category, but when I browse from static page to static page I don't see the different templates showing up.

Within the static pages plugin there is a readme that tells me to insert code into entries.tpl but I have no idea how this works. Anyone know what I'm doing wrong?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Category templates plugin with static pages

Post by garvinhicking »

Hi!

That in fact is not what the plugin is invented for.

Even though static pages can be associated to categories, that only applies to related entries showing up. It does NOT put a "staticpage" INSIDE a category.

Thus, the category templates plugin does NOT apply to staticpages. Staticpages always use the default blog template.

The only way to change that is ... well, actually creating an event plugin that checks on the current staticpage and change the template depending on this.

If you don't need a GUI for this (which would be quit ehard to create) a simple event plugin like this could do:

Code: Select all

<?php
if (IN_serendipity !== true) {
    die ("Don't hack!");
}

class serendipity_event_staticpagetemplates extends serendipity_event {
    var $title = 'Static Page Templates';
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',          $this->title);
        $propbag->add('author',        'Garvin Hicking');
        $propbag->add('version',       '0.01');
        $propbag->add('requirements',  array(
            'serendipity' => '1.3',
            'php'         => '4.3.0'
        ));
        $propbag->add('event_hooks',    array('genpage' => true));
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
                case 'genpage':
                    switch($_SERVER['REQUEST_URI']) {
                        case '/pages/staticpage.html':
                            $serendipity['template'] = 'contest';
                            break;

                        case '/pages/staticpage2.html':
                            $serendipity['template'] = 'carl_contest';
                            break;
                    }
                    break;
            }
        }
    }
}
Inside the $_SERVER['REQUEST_URI'] switch you need to add the URLs for your static pages and assign the template you want for it...

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

Ah, that looks kinda groovy, I'll give that a try, thanks
Post Reply