2015-06-16 08:11:03 +00:00
# HowTo: Create Themes
2023-08-10 10:10:01 +00:00
**Note:** You should read the [Module Reference ](./Modules.md ) and the [Template Reference ](./Templates.md ) before.
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
We assume you want to call your new theme `mytheme` .
Make sure you replace this by your module name everytime this is mentionend in this Howto.
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
## Creating the structure
At first create a new theme directory `themes/luci-theme-mytheme` .
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
Create a `Makefile` inside your theme directory with the following content:
```Makefile
include $(TOPDIR)/rules.mk
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
LUCI_TITLE:=Title of mytheme
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
include ../../luci.mk
# call BuildPackage - OpenWrt buildroot signature
```
2015-06-16 08:11:03 +00:00
Create the following directory structure inside your theme directory.
* ipkg
* htdocs
* luci-static
2023-08-10 10:10:01 +00:00
* `mytheme`
2015-06-16 08:11:03 +00:00
* luasrc
* view
* themes
2023-08-10 10:10:01 +00:00
* `mytheme`
2015-06-16 08:11:03 +00:00
* root
* etc
* uci-defaults
2023-08-10 10:10:01 +00:00
## Designing
Create two LuCI HTML-Templates named `header.htm` and `footer.htm` under `luasrc/view/themes/mytheme` .
The `header.htm` will be included at the beginning of each rendered page and the `footer.htm` at the end.
So your `header.htm` will probably contain a DOCTYPE description, headers,
the menu and layout of the page and the `footer.htm` will close all remaining open tags and may add a footer bar.
But hey that's your choice you are the designer ;-).
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
Just make sure your `header.htm` begins with the following lines:
```
< %
require("luci.http").prepare_content("text/html")
-%>
```
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
This makes sure your content will be sent to the client with the right content type.
Of course you can adapt `text/html` to your needs.
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
Put any stylesheets, Javascripts, images, ... into `htdocs/luci-static/mytheme` .
You should refer to this directory in your header and footer templates as: `<%=media%>` .
That means for a stylesheet `htdocs/luci-static/mytheme/cascade.css` you would write:
```html
< link rel = "stylesheet" type = "text/css" href = "<%=media%>/cascade.css" / >
```
2015-06-16 08:11:03 +00:00
2023-08-10 10:10:01 +00:00
## Making the theme selectable
2015-06-16 08:11:03 +00:00
If you are done with your work there are two last steps to do.
2023-08-10 10:10:01 +00:00
To make your theme OpenWrt-capable and selectable on the settings page you should now create a file `root/etc/uci-defaults/luci-theme-mytheme` with the following contents:
```sh
#!/bin/sh
uci batch < < -EOF
set luci.themes.MyTheme=/luci-static/mytheme
commit luci
EOF
exit 0
```
and another file `ipkg/postinst` with the following content:
```sh
#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] || {
( . /etc/uci-defaults/luci-theme-mytheme ) & & rm -f /etc/uci-defaults/luci-theme-mytheme
}
```
This is some OpenWrt magic to correctly register the template with LuCI when it gets installed.
2015-06-16 08:11:03 +00:00
That's all. Now send your theme to the LuCI developers to get it into the development repository - if you like.