2015-08-16 16:08:46 +00:00
# Themes
* [Home ](help )
To change the look of friendica you have to touch the themes.
2017-05-19 20:37:45 +00:00
The current default theme is [Vier ](https://github.com/friendica/friendica/tree/master/view/theme/vier ) but there are numerous others.
2015-08-16 16:08:46 +00:00
Have a look at [friendica-themes.com ](http://friendica-themes.com ) for an overview of the existing themes.
2015-08-17 07:17:36 +00:00
In case none of them suits your needs, there are several ways to change a theme.
2015-08-18 08:02:33 +00:00
So, how to work on the UI of friendica.
You can either directly edit an existing theme.
2015-08-16 16:08:46 +00:00
But you might loose your changes when the theme is updated by the friendica team.
2015-08-17 07:17:36 +00:00
If you are almost happy with an existing theme, the easiest way to cover your needs is to create a new theme, inheritating most of the properties of the parent theme and change just minor stuff.
2015-08-18 08:02:33 +00:00
The below for a more detailed description of theme heritage.
2015-08-16 16:08:46 +00:00
Some themes also allow users to select *variants* of the theme.
Those theme variants most often contain an additional [CSS ](https://en.wikipedia.org/wiki/CSS ) file to override some styling of the default theme values.
From the themes in the main repository *duepunto zero* and *vier* are using this methods for variations.
2015-08-17 07:17:36 +00:00
Quattro is using a slightly different approach.
2015-08-16 16:08:46 +00:00
Third you can start your theme from scratch.
Which is the most complex way to change friendicas look.
But it leaves you the most freedom.
2015-08-17 07:17:36 +00:00
So below for a *detailed* description and the meaning of some special files.
2015-08-16 16:08:46 +00:00
2015-08-17 07:17:36 +00:00
### Styling
2015-08-16 16:08:46 +00:00
If you want to change the styling of a theme, have a look at the themes CSS file.
In most cases, you can found these in
2015-08-17 07:17:36 +00:00
/view/theme/**your-theme-name**/style.css
2015-08-16 16:08:46 +00:00
sometimes, there is also a file called style.php in the theme directory.
This is only needed if the theme allowes the user to change certain things of the theme dynamically.
Say the font size or set a background image.
2015-08-17 07:17:36 +00:00
### Templates
2015-08-16 16:08:46 +00:00
If you want to change the structure of the theme, you need to change the templates used by the theme.
Friendica themes are using [SMARTY3 ](http://www.smarty.net/ ) for templating.
The default template can be found in
/view/templates
if you want to override any template within your theme create your version of the template in
2015-08-17 07:17:36 +00:00
/view/theme/**your-theme-name**/templates
2015-08-16 16:08:46 +00:00
any template that exists there will be used instead of the default one.
2015-08-17 07:17:36 +00:00
### Javascript
2015-08-16 16:08:46 +00:00
The same rule applies to the JavaScript files found in
/js
they will be overwritten by files in
2016-02-09 08:39:29 +00:00
/view/theme/**your-theme-name**/js.
2015-08-16 16:08:46 +00:00
## Expand an existing Theme
2015-08-17 07:17:36 +00:00
### Theme Variations
2018-01-25 14:00:23 +00:00
Many themes are more *theme families* than only one theme.
2015-08-17 07:17:36 +00:00
*duepunto zero* and *vier* allow easily to add new theme variation.
We will go through the process of creating a new variation for *duepunto zero* .
The same (well almost, some names change) procedure applies to the *vier* theme.
2018-01-25 14:00:23 +00:00
And similar steps are needed for *quattro* but this theme is using [lesscss ](http://lesscss.org/#docs ) to maintain the CSS files..
2015-08-16 16:08:46 +00:00
In
/view/theme/duepuntozero/deriv
you find a couple of CSS files that define color derivations from the duepunto theme.
These resemble some of the now as unsupported marked themes, that were inherited by the duepunto theme.
Darkzero and Easter Bunny for example.
The selection of the colorset is done in a combination of a template for a new form in the settings and aome functions in the theme.php file.
The template (theme_settings.tpl)
2015-08-17 07:17:36 +00:00
{{include file="field_select.tpl" field=$colorset}}
2015-08-16 16:08:46 +00:00
< div class = "settings-submit-wrapper" >
< input type = "submit" value = "{{$submit}}" class = "settings-submit" name = "duepuntozero-settings-submit" / >
< / div >
defines a formular consisting of a [select ](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select ) pull-down which contains all aviable variants and s submit button.
2018-01-25 14:00:23 +00:00
See the documentation about [SMARTY3 templates ](/help/snarty3-templates.md ) for a summary of friendica specific blocks other than the select element.
2015-08-17 07:17:36 +00:00
But we don't really need to change anything at the template itself.
2015-08-16 16:08:46 +00:00
2015-08-17 07:17:36 +00:00
The template alone wont work though.
2015-08-16 16:08:46 +00:00
You make friendica aware of its existance and tell it how to use the template file, by defining a config.php file.
2018-01-25 14:00:23 +00:00
It needs to define at least the following functions
2015-08-17 07:17:36 +00:00
2015-08-16 16:08:46 +00:00
* theme_content
* theme_post
and may also define functions for the admin interface
* theme_admin
* theme_admin_post.
theme_content and theme_admin are used to make the form available in the settings, repectively the admin panel.
The _post functions handle the processing of the send form, in this case they save to selected variand in friendicas database.
2015-08-17 07:17:36 +00:00
To make your own variation appear in the menu, all you need to do is to create a new CSS file in the deriv directoy and include it in the array in the config.php:
2015-08-16 16:08:46 +00:00
$colorset = array(
2018-01-21 16:38:01 +00:00
'default'=>L10n::t('default'),
'greenzero'=>L10n::t('greenzero'),
'purplezero'=>L10n::t('purplezero'),
'easterbunny'=>L10n::t('easterbunny'),
'darkzero'=>L10n::t('darkzero'),
'comix'=>L10n::t('comix'),
'slackr'=>L10n::t('slackr'),
2015-08-16 16:08:46 +00:00
);
the 1st part of the line is the name of the CSS file (without the .css) the 2nd part is the common name of the variant.
2018-01-21 16:38:01 +00:00
Calling the L10n::t() function with the common name makes the string translateable.
2015-08-16 16:08:46 +00:00
The selected 1st part will be saved in the database by the theme_post function.
2017-01-09 12:09:01 +00:00
function theme_post(App $a){
2015-08-16 16:08:46 +00:00
// non local users shall not pass
2016-12-20 10:56:34 +00:00
if (! local_user()) {
2015-08-16 16:08:46 +00:00
return;
2016-12-20 10:56:34 +00:00
}
2015-08-16 16:08:46 +00:00
// if the one specific submit button was pressed then proceed
if (isset($_POST['duepuntozero-settings-submit'])){
// and save the selection key into the personal config of the user
2020-01-18 15:54:50 +00:00
DI::pConfig()->set(local_user(), 'duepuntozero', 'colorset', $_POST['duepuntozero_colorset']);
2015-08-16 16:08:46 +00:00
}
}
2015-08-17 07:17:36 +00:00
Now that this information is set in the database, what should friendica do with it?
For this, have a look at the theme.php file of the *duepunto zero* .
2015-08-16 16:08:46 +00:00
There you'll find somethink alike
2020-01-18 15:50:57 +00:00
$colorset = DI::pConfig()->get( local_user(), 'duepuntozero','colorset');
2015-08-16 16:08:46 +00:00
if (!$colorset)
2017-11-07 02:22:52 +00:00
$colorset = Config::get('duepuntozero', 'colorset');
2015-08-16 16:08:46 +00:00
if ($colorset) {
if ($colorset == 'greenzero')
2019-12-30 22:35:01 +00:00
DI::page()['htmlhead'] .= '< link rel = "stylesheet" href = "view/theme/duepuntozero/deriv/greenzero.css" type = "text/css" media = "screen" /> '."\n";
2015-08-16 16:08:46 +00:00
/* some more variants */
}
2015-08-17 07:17:36 +00:00
which tells friendica to get the personal config of a user.
Check if it is set and if not look for the global config.
And finally if a config for the colorset was found, apply it by adding a link to the CSS file into the HTML header of the page.
So you'll just need to add a if selection, fitting your variant keyword and link to the CSS file of it.
2015-08-16 16:08:46 +00:00
Done.
Now you can use the variant on your system.
But remember once the theme.php or the config.php you have to readd your variant to them.
2015-08-17 07:17:36 +00:00
If you think your color variation could be benifical for other friendica users as well, feel free to generate a pull request at github so we can include your work into the repository.
2015-08-16 16:08:46 +00:00
### Inheritation
2017-05-19 20:37:45 +00:00
Say, you like the duepuntozero but you want to have the content of the outer columns left and right exchanged.
2015-08-16 16:08:46 +00:00
That would be not a color variation as shown above.
Instead we will create a new theme, duepuntozero_lr, inherit the properties of duepuntozero and make small changes to the underlying php files.
So create a directory called duepunto_lr and create a file called theme.php with your favorite text editor.
The content of this file should be something like
< ?php
/* meta informations for the theme, see below */
2018-05-07 16:28:55 +00:00
use Friendica\App;
2017-01-09 12:09:01 +00:00
function duepuntozero_lr_init(App $a) {
2015-08-16 16:08:46 +00:00
$a-> theme_info = array(
'extends' => 'duepuntozero'.
);
2017-11-11 09:26:23 +00:00
$a->set_template_engine('smarty3');
2015-08-16 16:08:46 +00:00
/* and more stuff e.g. the JavaScript function for the header */
}
Next take the default.php file found in the /view direcotry and exchange the aside and right_aside elements.
So the central part of the file now looks like this:
< body >
2018-11-30 14:06:22 +00:00
<?php if(!empty($page['nav'])) echo $page['nav']; ?>
< aside > <?php if(!empty($page['right_aside'])) echo $page['right_aside']; ?> < / aside >
< section > <?php if(!empty($page['content'])) echo $page['content']; ?>
2015-08-16 16:08:46 +00:00
< div id = "page-footer" > < / div >
< / section >
2018-11-30 14:06:22 +00:00
< right_aside > <?php if(!empty($page['aside'])) echo $page['aside']; ?> < / right_aside >
< footer > <?php if(!empty($page['footer'])) echo $page['footer']; ?> < / footer >
2015-08-16 16:08:46 +00:00
< / body >
Finally we need a style.css file, inheriting the definitions from the parent theme and containing out changes for the new theme.
2015-08-17 07:17:36 +00:00
***Note***:You need to create the style.css and at lest import the base CSS file from the parent theme.
2015-08-16 16:08:46 +00:00
@import url('../duepuntozero/style.css');
Done.
But I agree it is not really useful at this state.
2015-08-17 07:17:36 +00:00
Nevertheless, to use it, you just need to activate in the admin panel.
2015-08-16 16:08:46 +00:00
That done, you can select it in the settings like any other activated theme.
## Creating a Theme from Scratch
Keep patient.
2017-05-19 20:37:45 +00:00
Basically what you have to do is identify which template you have to change so it looks more like what you want.
2015-08-16 16:08:46 +00:00
Adopt the CSS of the theme accordingly.
And iterate the process until you have the theme the way you want it.
2018-03-03 14:47:36 +00:00
*Use the source Luke.* and don't hesitate to ask in @[developers](https://forum.friendi.ca/profile/developers) or @[helpers](https://forum.friendi.ca/profile/helpers).
2015-08-17 07:17:36 +00:00
2015-08-16 16:08:46 +00:00
## Special Files
### unsupported
2015-08-18 08:02:33 +00:00
If a file with this name (which might be empty) exists in the theme directory, the theme is marked as *unsupported* .
2015-08-16 16:08:46 +00:00
An unsupported theme may not be selected by a user in the settings.
Users who are already using it wont notice anything.
### README(.md)
The contents of this file, with or without the .md which indicates [Markdown ](https://daringfireball.net/projects/markdown/ ) syntax, will be displayed at most repository hosting services and in the theme page within the admin panel of friendica.
This file should contain information you want to let others know about your theme.
### screenshot.[png|jpg]
If you want to have a preview image of your theme displayed in the settings you should take a screenshot and save it with this name.
Supported formats are PNG and JPEG.
### theme.php
This is the main definition file of the theme.
2018-01-25 14:00:23 +00:00
In the header of that file, some meta information is stored.
2015-08-16 16:08:46 +00:00
For example, have a look at the theme.php of the *quattro* theme:
< ?php
/**
* Name: Quattro
* Version: 0.6
* Author: Fabio < http: // kirgroup . com / profile / fabrixxm >
* Maintainer: Fabio < http: // kirgroup . com / profile / fabrixxm >
* Maintainer: Tobias < https: // f . diekershoff . de / profile / tobias >
*/
2018-01-25 14:00:23 +00:00
You see the definition of the theme's name, it's version and the initial author of the theme.
2017-05-19 20:37:45 +00:00
These three pieces of information should be listed.
If the original author is no longer working on the theme, but a maintainer has taken over, the maintainer should be listed as well.
2018-01-25 14:00:23 +00:00
The information from the theme header will be displayed in the admin panel.
2015-08-16 16:08:46 +00:00
2018-05-07 16:28:55 +00:00
The first thing in file is to import the `App` class from `\Friendica\` namespace.
use Friendica\App;
This will make our job a little easier, as we don't have to specify the full name every time we need to use the `App` class.
2017-05-19 20:37:45 +00:00
The next crucial part of the theme.php file is a definition of an init function.
2015-08-16 16:08:46 +00:00
The name of the function is < theme-name > _init.
So in the case of quattro it is
2017-01-09 12:09:01 +00:00
function quattro_init(App $a) {
2015-08-16 16:08:46 +00:00
$a->theme_info = array();
2017-11-11 09:26:23 +00:00
$a->set_template_engine('smarty3');
2015-08-16 16:08:46 +00:00
}
2017-05-19 20:37:45 +00:00
Here we have set the basic theme information, in this case they are empty.
2015-08-16 16:08:46 +00:00
But the array needs to be set.
And we have set the template engine that should be used by friendica for this theme.
At the moment you should use the *smarty3* engine.
There once was a friendica specific templating engine as well but that is not used anymore.
If you like to use another templating engine, please implement it.
When you want to inherit stuff from another theme you have to *announce* this in the theme_info:
$a->theme_info = array(
'extends' => 'duepuntozero',
);
which declares *duepuntozero* as parent of the theme.
If you want to add something to the HTML header of the theme, one way to do so is by adding it to the theme.php file.
To do so, add something alike
2019-12-30 22:35:01 +00:00
DI::page()['htmlhead'] .= < < < EOT
2015-08-16 16:08:46 +00:00
/* stuff you want to add to the header */
EOT;
The $a variable holds the friendica application.
So you can access the properties of this friendica session from the theme.php file as well.
### default.php
This file covers the structure of the underlying HTML layout.
The default file is in
/view/default.php
2015-08-16 16:18:01 +00:00
if you want to change it, say adding a 4th column for banners of your favourite FLOSS projects, place a new default.php file in your theme directory.
2017-05-19 20:37:45 +00:00
As with the theme.php file, you can use the properties of the $a variable with holds the friendica application to decide what content is displayed.