Skip to main content
Topic: [ADDON] Pages (Read 5098 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[ADDON] Pages

Here's a very simple addon that extends Elkarte to allow custom actions/templates for creating basic custom pages away from the core.

https://github.com/Xydre/elkarte-pages

  • Create a /custom/ directory
  • Populate /custom/ with a JSON encoded file named "pages.json", and a sources and themes directories in the same layout as the core
  • Add a controller to /custom/sources/controllers/
  • Add a template to /custom/themes/<theme name>/
  • Call loadCustomTemplate from the controller instead of loadTemplate
  • Other custom versions of load functions can be found in the controller in the addon package

Example pages.json:
Code: [Select]
{
  "test": [
    "Test.controller.php",
    "Test_Controller",
    "action_index"
  ],
  "mumble": [
    "Mumble.controller.php",
    "Mumble_Controller",
    "action_index"
  ]
}

Custom pages are accessed from index.php?action=pages;pa=<custom page action from pages.json>

The /custom/ directory follows the same structure as the core to allow multiple theme templates and subs files/classes alongside controllers.

Eager to here any suggestions or improvements. This addon aims to make custom pages far easier to implement than writing entire addon packages each time you want a custom action.
Last Edit: February 26, 2015, 02:40:59 pm by ant59

Re: [ADDON] Pages

Reply #1

That sounds awesome!

 emanuele needs to try it!
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] Pages

Reply #2

Thats a great approach, the only thing that would be better is if I had thought of it :D  

I don't immediately see any problems with the approach at all, it looks at though it should be pretty seamless.

Re: [ADDON] Pages

Reply #3

Thanks :)

I wanted a way to hook directly into the power of the core Elkarte functions and templating system rather than basic SSI pages.

Re: [ADDON] Pages

Reply #4

Small suggestion: it may be worth adding an empty json file to the package, some servers may not like to create new files via php and not having one may return an error in file_get_contents.
I think. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] Pages

Reply #5

Good thinking, I'll add a blank pages.json :)


Re: [ADDON] Pages

Reply #7

Quote from: emanuele – Small suggestion: it may be worth adding an empty json file to the package, ...

And put an example page into the package please! I want to add a Google Map to our board and don't know how!  ;D

Re: [ADDON] Pages

Reply #8

Quote from: Jorin – And put an example page into the package please! I want to add a Google Map to our board and don't know how!  ;D

No one who works with this addon an can post a standard empty page? Or is it that simple to create one that I should just try it?  ;)

Re: [ADDON] Pages

Reply #9

If I'm not wrong, something like this should work:
Code: (Test.controller.php) [Select]
<?php

class Test_Controller
{
    function action_index()
    {
        global $context;

        loadCustomTemplate('Test');
        $context['sub_template'] = 'test';
    }
}

Code: (Test.template.php) [Select]
<?php

function template_test()
{
    echo 'something';
}
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] Pages

Reply #10

I'm investigating this as an alternative to writing or porting something like Bakers Dozen Pages myself. I have attached a working /custom file structure, but of course the @import in /custom/themes/default/css/index.css is silly at best and hostile to theme switching at worst. Is there something I could add in the controller or something?


Re: [ADDON] Pages

Reply #12

Ah, thank you. So then we get something like this (and it works):

Code: (Test.controller.php) [Select]
<?php

class Test_Controller
{
    function action_index()
    {
        global $context;

        loadCustomTemplate('Test');
        loadCSSFile('index.css');
        $context['sub_template'] = 'test';
    }
}

I reckon I'll combine it with Ultimate Menu for adding a few simple pages (just some HTML really). The Bakers Dozen Pages approach is simpler, but at the same time this is at least potentially far more flexible. :)