Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2020-01-05 22:19:25

From: Leeds, UK
Registered: 2006-01-29
Posts: 9,832

Re: How to for writers

jakob wrote #320854:

Nice! Can you elaborate on this?

Certainly. In your theme’s .php file, just after the class opening definition, add a constructor:

public function __construct()
    if (!has_handler('abc_dashboard')) {
        add_privs('tab.start', '1,2,3,4,5,6');
        add_privs('abc_dashboard', '1,2,3,4,5,6');
        register_tab('start', 'abc_dashboard', 'My Dashboard');
        register_callback(array($this, 'draw'), 'abc_dashboard');

    $this_theme = str_replace('_theme', '', __CLASS__);

Then, somewhere within your theme’s class, define your draw() method that will render your initial tab contents:

public function draw($evt, $stp)
    echo pagetop();
    echo '<h1>Hello dashboard world</h1>';
    echo '<p>Pleased to meet you!</p>';

Job done. Rinse and repeat the callback/tab registration in the conditional inside your constructor with as many tabs as you like and pass control of each to their own method.

You can use all plugin-type features here: even steps if you wish so you can show different content based on the &step= in the URL. That would enable you to have one draw() method and differentiate on the step instead.

The above is all smd_tabber does, just wrapping this up with some UI fluff.

If you want to defer control of content to a page, then use something like this in your draw() method (untested):

include_once txpath.'/publish.php';

$html = fetch_page('some-page', 'some-public-theme');
echo parse($html);

That should get you going.

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp


Board footer

Powered by FluxBB