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:
{
"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.
That sounds awesome!
/me needs to try it!
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.
Thanks :)
I wanted a way to hook directly into the power of the core Elkarte functions and templating system rather than basic SSI pages.
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. ;)
Good thinking, I'll add a blank pages.json :)
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? ;)
If I'm not wrong, something like this should work:
<?php
class Test_Controller
{
function action_index()
{
global $context;
loadCustomTemplate('Test');
$context['sub_template'] = 'test';
}
}
<?php
function template_test()
{
echo 'something';
}
http://elkarte.github.io/Doc/function-loadCSSFile.html is your friend.
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. :)