Skip to content

Add-on / Folder Structure

Add-on / Folder Structure

Heads Up!

Make sure you get this structure right from the start. The loader will only check those folders and whatever files/folders you require/include from there. The following example expects the add-on name to be example_addon this will be important for a lot of functions used by the add-on loader.

example_addon
|
├- assets
|   └- style.css
|   
|- views
|   ├- droplinks.blade.php
|   ├- sidebar.blade.php
|   └- example_addon.blade.php
|
└- plugin.php

plugin.php - Your add-ons main file

This is the only file which is always and directly injected into the main app. From here you can require & include additional files add routes and more. Depending on your preference this is where you can add routes that your add-on will use, here's an example:

<?php
    use Pecee\SimpleRouter\SimpleRouter;

    // Add a route which allows the method /GET
    SimpleRouter::get('/c/hello-world', function(){
        echo 'Hello World!';
    });
As you can see, adding routes is fairly easy. If you would now visit https://example.com/c/hello-world the url would return Hello World! Since this doesn't look too fancy you can make use of Blade templates and directly extend the master template lethal.landing uses, interested? Head over to Adding Views to find out more. You can find out more information about Skipperbents SimpleRouter here.

style.css - Globally used stylesheet

This includes css styling across lethal.landing in a whole! If your add-on only adds new styling to a few of your views try using inline styling wherever possible because it would improve performance over adding your custom styling on all pages, even default ones.

/views - Extend lethal.landings default looks

Instead of returning just plain text you can extend lethal.landings default looks. Below you can see an example on how to return a template instead.

<?php
    use Pecee\SimpleRouter\SimpleRouter;

    // $tpl is a globally defined instance of 
    global $tpl;
    // Add a route which allows the method /GET and cast $tpl to the function
    SimpleRouter::get('/c/hello-world', function($tpl){
        // Run an return the template.
        return $tpl->run('example_addon.views.example_addon');
    });

droplinks.blade.php - HTML in this file will be appended to the user drop down

<li>
    <a class="dropdown-item droplink-item" href="#">Example User Link</a>
</li>

sidebar.blade.php - HTML in this file will be added to the admin areas sidebar

<li class="nav-link-h">
    <div class="dropup">
        <a class="sidebar-sub-submenu nav-link py-3" data-bs-toggle="dropdown" aria-expanded="false">
        <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="Example Add-on">
            <!-- Set an icon for your add-on -->
            <i class="fas fa-2x fa-fw fa-heart"></i>
        </span>
        </a>
        <ul class="dropdown-menu sidebar-sub-submenu-open">
            <!-- Add items in its drop-up like so -->
            <li class="nav-link-h">
                <a href="{{absURL()}}r/settings/plugin/example_plugin" class="nav-link py-3" data-bs-toggle="tooltip" data-bs-placement="top" title="Add-on Settings">
                    <i class="fas fa-2x fa-fw fa-wrench"></i>
                </a>
            </li>

            <li class="nav-link-h">
                <a href="" class="nav-link py-3" data-bs-toggle="tooltip" data-bs-placement="top" title="Another Link">
                    <i class="fas fa-2x fa-fw fa-link"></i>
                </a>
            </li>

        </ul>
    </div>
</li>

example_addon.blade.php

The example_addon.blade.php holds the html code you want to use in a page for your addon. It is of course possible to have multiple pages but remember to that you must add routes for them!

Please head over to Adding Views for a more in-depth explanation on how it works.