]> git.mxchange.org Git - friendica.git/blob - doc/themes.md
ec3a76ac289a472088350110335ee2d60a317062
[friendica.git] / doc / themes.md
1 # Themes
2
3 * [Home](help)
4
5 To change the look of friendica you have to touch the themes.
6 The current default theme is [duepunto zero](https://github.com/friendica/friendica/tree/master/view/theme/duepuntozero) but there are numerous others.
7 Have a look at [friendica-themes.com](http://friendica-themes.com) for an overview of the existing themes.
8 In case none of them suits your needs, there are several ways to change a theme.
9 If you need help theming, there is a forum @[ftdevs@friendica.eu](https://friendica.eu/profile/ftdevs) where you can ask theme specific questions and present your themes.
10
11 So, how to work on the UI of friendica.
12
13 You can either directly edit an existing theme.
14 But you might loose your changes when the theme is updated by the friendica team.
15
16 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.
17 The below for a more detailed description of theme heritage.
18
19 Some themes also allow users to select *variants* of the theme.
20 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.
21 From the themes in the main repository *duepunto zero* and *vier* are using this methods for variations.
22 Quattro is using a slightly different approach.
23
24 Third you can start your theme from scratch.
25 Which is the most complex way to change friendicas look.
26 But it leaves you the most freedom.
27 So below for a *detailed* description and the meaning of some special files.
28
29 ### Styling
30
31 If you want to change the styling of a theme, have a look at the themes CSS file.
32 In most cases, you can found these in
33
34     /view/theme/**your-theme-name**/style.css
35
36 sometimes, there is also a file called style.php in the theme directory.
37 This is only needed if the theme allowes the user to change certain things of the theme dynamically.
38 Say the font size or set a background image.
39
40 ### Templates
41
42 If you want to change the structure of the theme, you need to change the templates used by the theme.
43 Friendica themes are using [SMARTY3](http://www.smarty.net/) for templating.
44 The default template can be found in
45
46     /view/templates
47
48 if you want to override any template within your theme create your version of the template in
49
50     /view/theme/**your-theme-name**/templates
51
52 any template that exists there will be used instead of the default one.
53
54 ### Javascript
55
56 The same rule applies to the JavaScript files found in
57
58     /js
59
60 they will be overwritten by files in
61
62     /view/theme/**your-theme-name**/js
63
64 ### Modules
65
66 You have the freedom to override core modules found in
67
68     /mod
69
70 They will be overwritten by files in
71
72     /view/theme/**your-theme-name**/mod
73
74 Be aware that you can break things easily here if you don't know what you do. Also notice that you can override parts of the module – functions not defined in your theme module will be loaded from the core module.
75
76 ## Expand an existing Theme
77
78 ### Theme Variations
79
80 Many themes are more *theme families* then only one theme.
81 *duepunto zero* and *vier* allow easily to add new theme variation.
82 We will go through the process of creating a new variation for *duepunto zero*.
83 The same  (well almost, some names change) procedure applies to the *vier* theme.
84 And similar steps are needed for *quattro* but this theme is using [lessc](http://lesscss.org/#docs) to maintaine the CSS files..
85
86 In
87
88     /view/theme/duepuntozero/deriv
89
90 you find a couple of CSS files that define color derivations from the duepunto theme.
91 These resemble some of the now as unsupported marked themes, that were inherited by the duepunto theme.
92 Darkzero and Easter Bunny for example.
93
94 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.
95 The template (theme_settings.tpl)
96
97     {{include file="field_select.tpl" field=$colorset}}
98     <div class="settings-submit-wrapper">
99         <input type="submit" value="{{$submit}}" class="settings-submit" name="duepuntozero-settings-submit" />
100     </div>
101
102 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.
103 See the documentation about [SMARTY3 templates](/help/snarty3-templates.md) for a summary of friendica specific blocks other then the select element.
104 But we don't really need to change anything at the template itself.
105
106 The template alone wont work though.
107 You make friendica aware of its existance and tell it how to use the template file, by defining a config.php file.
108 It needs to define at lest the following functions
109
110 * theme_content
111 * theme_post
112
113 and may also define functions for the admin interface
114
115 * theme_admin
116 * theme_admin_post.
117
118 theme_content and theme_admin are used to make the form available in the settings, repectively the admin panel.
119 The _post functions handle the processing of the send form, in this case they save to selected variand in friendicas database.
120
121 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:
122
123     $colorset = array(
124         'default'=>t('default'),
125         'greenzero'=>t('greenzero'),
126         'purplezero'=>t('purplezero'),
127         'easterbunny'=>t('easterbunny'),
128         'darkzero'=>t('darkzero'),
129         'comix'=>t('comix'),
130         'slackr'=>t('slackr'),
131     );
132
133 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.
134 Calling the t() function with the common name makes the string translateable.
135 The selected 1st part will be saved in the database by the theme_post function.
136
137     function theme_post(&$a){
138         // non local users shall not pass
139         if(! local_user())
140             return;
141         // if the one specific submit button was pressed then proceed
142         if (isset($_POST['duepuntozero-settings-submit'])){
143             // and save the selection key into the personal config of the user
144             set_pconfig(local_user(), 'duepuntozero', 'colorset', $_POST['duepuntozero_colorset']);
145         }
146     }
147
148 Now that this information is set in the database, what should friendica do with it?
149 For this, have a look at the theme.php file of the *duepunto zero*.
150 There you'll find somethink alike
151
152         $colorset = get_pconfig( local_user(), 'duepuntozero','colorset');
153         if (!$colorset)
154             $colorset = get_config('duepuntozero', 'colorset');
155         if ($colorset) {
156             if ($colorset == 'greenzero')
157                 $a->page['htmlhead'] .= '<link rel="stylesheet" href="view/theme/duepuntozero/deriv/greenzero.css" type="text/css" media="screen" />'."\n";
158             /* some more variants */
159         }
160
161 which tells friendica to get the personal config of a user.
162 Check if it is set and if not look for the global config.
163 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.
164 So you'll just need to add a if selection, fitting your variant keyword and link to the CSS file of it.
165
166 Done.
167 Now you can use the variant on your system.
168 But remember once the theme.php or the config.php you have to readd your variant to them.
169 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.
170
171 ### Inheritation
172
173 Say, you like the duepuntozero but you want to have the content of the outer columns  left and right exchanged.
174 That would be not a color variation as shown above.
175 Instead we will create a new theme, duepuntozero_lr, inherit the properties of duepuntozero and make small changes to the underlying php files.
176
177 So create a directory called duepunto_lr and create a file called theme.php with your favorite text editor.
178 The content of this file should be something like
179
180     <?php
181     /* meta informations for the theme, see below */
182     function duepuntozero_lr_init(&$a) {
183         $a-> theme_info = array(
184             'extends' => 'duepuntozero'.
185         );
186         set_template_engine($a, 'smarty3');
187         /* and more stuff e.g. the JavaScript function for the header */
188     }
189
190 Next take the default.php file found in the /view direcotry and exchange the aside and right_aside elements.
191 So the central part of the file now looks like this:
192
193     <body>
194         <?php if(x($page,'nav')) echo $page['nav']; ?>
195         <aside><?php if(x($page,'right_aside')) echo $page['right_aside']; ?></aside>
196         <section><?php if(x($page,'content')) echo $page['content']; ?>
197                 <div id="page-footer"></div>
198         </section>
199         <right_aside><?php if(x($page,'aside')) echo $page['aside']; ?></right_aside>
200         <footer><?php if(x($page,'footer')) echo $page['footer']; ?></footer>
201     </body>
202
203 Finally we need a style.css file, inheriting the definitions from the parent theme and containing out changes for the new theme.
204 ***Note***:You need to create the style.css and at lest import the base CSS file from the parent theme.
205
206     @import url('../duepuntozero/style.css');
207
208 Done.
209 But I agree it is not really useful at this state.
210 Nevertheless, to use it, you just need to activate in the admin panel.
211 That done, you can select it in the settings like any other activated theme.
212
213 ## Creating a Theme from Scratch
214
215 Keep patient.
216 Basically what you have to do is identifying which template you have to change so it looks more like what you want.
217 Adopt the CSS of the theme accordingly.
218 And iterate the process until you have the theme the way you want it.
219
220 *Use the source Luke.* and don't hesitate to ask in @[ftdevs](https://friendica.eu/profile/ftdevs) or @[helpers](https://helpers.pyxis.uberspace.de/profile/helpers).
221
222 ## Special Files
223
224 ### unsupported
225
226 If a file with this name (which might be empty) exists in the theme directory, the theme is marked as *unsupported*.
227 An unsupported theme may not be selected by a user in the settings.
228 Users who are already using it wont notice anything.
229
230 ### README(.md)
231
232 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.
233
234 This file should contain information you want to let others know about your theme.
235
236 ### screenshot.[png|jpg]
237
238 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.
239 Supported formats are PNG and JPEG.
240
241 ### theme.php
242
243 This is the main definition file of the theme.
244 In the header of that file, some meta information are stored.
245 For example, have a look at the theme.php of the *quattro* theme:
246
247     <?php
248     /**
249      * Name: Quattro
250      * Version: 0.6
251      * Author: Fabio <http://kirgroup.com/profile/fabrixxm>
252      * Maintainer: Fabio <http://kirgroup.com/profile/fabrixxm>
253      * Maintainer: Tobias <https://f.diekershoff.de/profile/tobias>
254      */
255
256 You see the definition of the themes name, it's version and the initial author of the theme.
257 These three information should be listed.
258 If the original author is not anymore working on the theme, but a maintainer has taken over, the maintainer should be listed as well.
259 The information from the theme header will be displayed in the admin panelö.
260
261 Next crucial part of the theme.php file is a definition of an init function.
262 The name of the function is <theme-name>_init.
263 So in the case of quattro it is
264
265     function quattro_init(&$a) {
266       $a->theme_info = array();
267       set_template_engine($a, 'smarty3');
268     }
269
270 Here we have set the basic theme information, in this case they are empthy.
271 But the array needs to be set.
272 And we have set the template engine that should be used by friendica for this theme.
273 At the moment you should use the *smarty3* engine.
274 There once was a friendica specific templating engine as well but that is not used anymore.
275 If you like to use another templating engine, please implement it.
276
277 When you want to inherit stuff from another theme you have to *announce* this in the theme_info:
278
279     $a->theme_info = array(
280       'extends' => 'duepuntozero',
281     );
282
283 which declares *duepuntozero* as parent of the theme.
284
285 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.
286 To do so, add something alike
287
288     $a->page['htmlhead'] .= <<< EOT
289     /* stuff you want to add to the header */
290     EOT;
291
292 The $a variable holds the friendica application.
293 So you can access the properties of this friendica session from the theme.php file as well.
294
295 ### default.php
296
297 This file covers the structure of the underlying HTML layout.
298 The default file is in
299
300     /view/default.php
301
302 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.
303 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.