Templates
Create new template
So you want to create a template for MyAAC? That's pretty straightforward!
Templates are placed under templates/ folder in the MyAAC installation.
Notice: there is also system/templates folder, that serves for different purposes. It is used for HTML Twig templates. Let's distinguish between those two
This tutorial is targeted against version 0.8 and higher of MyAAC. It won't work with 0.7, because there were some incompatibilities being introduced between the releases, like now you use config('key')
function instead of the global variable $config['key']
.
Naming convention
Your main template file where header, footer and content (generally whole HTML structure) are stored should be named index.php. And it should be placed inside your template folder like this: templates/example/index.php, where example is your template name.
Images can be placed into templates/example/images but that's up to you how you name the folder. Same with CSS and JavaScript, it's up to you where you place them.
Protect the script
At the beginning of your template index.php file add this:
This protects the script from being directly accessed by browser.
Configuration (config.ini & config.php)
If you have something that you want to make for the users configurable, you can place it in config.ini or config.php of your template folder.
If you want your template to be compatible with MyAAC 0.7 and lower, then you need to either create config.ini or config.php, both cannot exist cause they won't be loaded by MyAAC!
Syntax of ini is very easy (simple key=value). And its being internally parsed by PHP function parse_ini_file
Example of config.ini
Then in your template (index.php) you can use for example:
Or:
Content
Now we came to the most visible part of the page. Content. Content is something that dynamically changes between pages. Create account, highscores and downloads page are examples of content.
To place this content on your website use the $content
variable in your template.
Example:
As wrote, $content
will be dynamically generated with every page refresh and will include the main content of the page.
Placeholders
MyAAC automatically generates some HTML code for your template to make it easier to develop plugins that can automatically inject code into it. This is:
META tags (like title, charset, content-language, description and keywords based on configuration)
jQuery, ReCaptcha and other JavaScript tags
some CSS stuff
Like wrote, jQuery is automatically included with every template that includes placeholders, so you don't need to include it in your script.
There are 3 place holders that are mandatory (without them your template won't work correctly). Those are: head_start
, head_end
and body_end
.
To include placeholder in your template, just use following PHP Code:
Placeholders needs to be located in following places:
<?php echo template_place_holder('head_start'); ?>
just after opening<head>
<?php echo template_place_holder('head_end'); ?>
just before closing</head>
<?php echo template_place_holder('body_end'); ?>
just before closing</body>
Optional placeholders
Some optional placeholder is center_top
.
Its used for example by the plugins Welcome Box or Powerful guilds. Plugins can inject here some code that will be displayed just before the $content
.
Its typical to mix them in one line, so usually you should have something like this:
Status
You may wish to add status of the server to your template. For this, you can use the $status
variable.
Example:
Except that, you can use following array-keys:
Notice: Some of these variables are available only if the server is online (
$status['online'] = true
), so you need to check the status first before using them.
Functions
In your template you can use some helper functions that are specially made for templates.
config(key), configLua(key)
Get config option from MyAAC config, or from server .lua file.
Notice: only MyAAC 0.8 and higher
Example:
getLink(name)
Use it to generate links to your pages.
Example:
template_form()
Use it to place a form on the page where user can change template. Its good practice to make it configurable.
Example:
template_footer()
Use it to place auto-generated footer on the website. It includes page load time, visitors, copyright notices and famous "Powered by MyAAC." text.
Example: (taken from ShadowCores templates)
getTopPlayers($amount)
Use it go get top players of the server, wherever you can specify $amount yourself. This function automatically caches the result, so you don't need to care about performance.
Example:
tickers()
Use it to place the tickers on the page.
Example:
For more functions look into system/functions.php
Tipps
Display server IP/domain:
For displaying server IP or domain you can use PHP built-in variable $_SERVER['SERVER_NAME']
;
Example:
Display client version:
Use $config['client']
divided by 100.
Example:
Display images or include style/javascript to your template folder.
If you place files under your template folder, you can refer to them with the $template_path
variable.
Normally, you would do it like this:
But imagine, if you change the name of your template from example, to something else, like example2.
Then you will need to replace all templates/example in your template! That's may introduce a lot of useless work!
For this, you can use built-in $template_path
variable.
So, instead do this this way:
Do same, with including javascript:
Last updated