ElkArte Community

Extending Elk => Addons => Topic started by: Ant59 on February 26, 2015, 07:08:47 am

Title: [ADDON] Pages
Post by: Ant59 on February 26, 2015, 07:08:47 am
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


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.
Title: Re: [ADDON] Pages
Post by: emanuele on February 26, 2015, 07:27:59 am
That sounds awesome!

/me needs to try it!
Title: Re: [ADDON] Pages
Post by: Spuds on February 26, 2015, 01:26:13 pm
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.
Title: Re: [ADDON] Pages
Post by: Ant59 on February 26, 2015, 05:17:54 pm
Thanks :)

I wanted a way to hook directly into the power of the core Elkarte functions and templating system rather than basic SSI pages.
Title: Re: [ADDON] Pages
Post by: emanuele on March 01, 2015, 07:15:39 am
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. ;)
Title: Re: [ADDON] Pages
Post by: Ant59 on March 01, 2015, 03:02:20 pm
Good thinking, I'll add a blank pages.json :)
Title: Re: [ADDON] Pages
Post by: meetdilip on March 02, 2015, 10:07:36 am
Awesome !! @ant59
Title: Re: [ADDON] Pages
Post by: Jorin on March 06, 2015, 12:57:58 am
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
Title: Re: [ADDON] Pages
Post by: Jorin on March 13, 2015, 02:13:42 am
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?  ;)
Title: Re: [ADDON] Pages
Post by: emanuele on March 13, 2015, 03:18:28 pm
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';
}
Title: Re: [ADDON] Pages
Post by: Frenzie on April 05, 2016, 08:50:20 am
I'm investigating this as an alternative to writing or porting something like Bakers Dozen Pages (http://custom.simplemachines.org/mods/index.php?mod=1477) 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?
Title: Re: [ADDON] Pages
Post by: TE on April 05, 2016, 11:25:22 am
http://elkarte.github.io/Doc/function-loadCSSFile.html is your friend.
Title: Re: [ADDON] Pages
Post by: Frenzie on April 05, 2016, 11:36:21 am
Ah, thank you. So then we get something like this (and it works):

<?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 (http://addons.elkarte.net/enhancement/Ultimate-Menu.html) 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. :)