- Posts: 241
Before asking for help please read "How to request help" by clicking on that tab above here."
Question [SOLVED] how to add/modify a theme?
- jopla
- Topic Author
- Offline
- Junior Member
I like to modify a theme. Earlier I modified the theme itself but with the new release my changes are gone.
Somebody told me that I have to make a copy of the "_custom" directory to f.e. "mytheme" and put there the changes.
But as soon I made a copy of that directory the whole webtreessite doesn't work anymore. Have I to webtrees anywhere else also that there will be a new theme?
Thanks for reaction.
Jop
Please Log in or Create an account to join the conversation.
- JustCarmen
- Offline
- Elite Member
Carmen
Designer of the JustLight theme (comes with a light and dark color palette), Fancy Imagebar, Fancy Research Links and Fancy Treeview for webtrees 2
Check my website at www.justcarmen.nl
Please Log in or Create an account to join the conversation.
- Jackie
- Offline
- Platinum Member
- Posts: 4787
The answer posted here would help others..
Do we need « How to customise a theme? » in the Wiki - category Customising ?
wiki.webtrees.net/en/Category:Customising_webtrees
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
Please Log in or Create an account to join the conversation.
- Jackie
- Offline
- Platinum Member
- Posts: 4787
Carmen posted that she sent you the answer by email.
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
Please Log in or Create an account to join the conversation.
- Jackie
- Offline
- Platinum Member
- Posts: 4787
Did you rename the folder _custom when you copied it?
e.g. _custom = joplatheme
Did you change the first line of the file theme.php with your theme's name?
namespace MyNamespace\MyProject;
should become:
namespace Joplatheme\webtrees;
EDIT: In the file theme.php, you should change the name _custom with your theme's name e.g. joplatheme, everywhere you see it.
Please Log in or Create an account to join the conversation.
- fisharebest
- Offline
- Administrator
That is correct.
What changes did you make?
> But as soon I made a copy of that directory the whole webtreessite doesn't work anymore.
I guess there was an error in your changes.
"doesn't work anymore". What does this mean? Do you get an error message?
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
There is a problem with the copying of the _custom dir. Or more with the theme.php. If there are 2 theme.php (1 in _custom and 1 in theme_jop) the site crashs.
If I rename the theme.php in _custom to theme.php.org than there is placed a new theme.php at the update and the site will crash again ...
Please Log in or Create an account to join the conversation.
- fisharebest
- Offline
- Administrator
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
1. if you make a copy of the _custom directory there will be 2 theme.php files and that will give any php error.
2. if you rename the _custom directory there will be installed at update a new _custom directory with again a 2nd theme.php file -> error
so, if you keep the _custom directory and change the theme.php, can I be sure that the theme.php will be not overwrite at update by the original?
Please Log in or Create an account to join the conversation.
- fisharebest
- Offline
- Administrator
It is OK to have many "theme.php" files.
There exists:
clouds/theme.php
colors/theme.php
fab/theme.php
minimal/theme.php
webtrees/theme.php
xenea/theme.php
This is not your error.
Look in your webserver error logs. You will see the exact error.
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
fisharebest wrote: > if you make a copy of the _custom directory there will be 2 theme.php files and that will give any php error.
Look in your webserver error logs. You will see the exact error.
How?
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
fisharebest wrote: > if you make a copy of the _custom directory there will be 2 theme.php files and that will give any php error.
It is OK to have many "theme.php" files.
Maybe, but probably there will be used in _custom/theme.php and theme_jop/theme.php the same varianles or objects or something like that.
Or two times "return new MyTheme".
Maybe you cannot create a new object if the object allready excist?
Or have I to modyfy this line also:
namespace MyNamespace\MyProject;
in f.e.
namespace MyNamespace\Theme_Jop_Project;
?
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
You have to change the namespace-name. Maybe somebody can write a short manual how to make your own profile?
Please Log in or Create an account to join the conversation.
- fisharebest
- Offline
- Administrator
If you post the answer here, it may help others with the same problem.
Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
PS. You was to fast with your reply, see above.
Please Log in or Create an account to join the conversation.
- JustCarmen
- Offline
- Elite Member
The answer posted here would help others..
Yes, Jackie I know. But I'd just answered his questions in Dutch (because he wrote to me in Dutch) when I saw his message here. If I had the time I would have translated it here but I was in a hurry, sorry.
You just asked me some questions which I've answered but I can't help if it wasn't the whole solution when I only get parts of the story.But if the answer is not the solution .... ?
But tonight you sent me your theme file to look at it. And as I said earlier you are on the right track. Only one little change needed to get it working:
Sorry I can't show the changes inside the code block but I have changed your code in two places. Class MyTheme is changed in Class ThemeJop and at the bottom I have changed 'return new MyTheme' in 'return new ThemeJop'.
Your script wasn't working because the class 'MyTheme' already existed.
Carmen
Designer of the JustLight theme (comes with a light and dark color palette), Fancy Imagebar, Fancy Research Links and Fancy Treeview for webtrees 2
Check my website at www.justcarmen.nl
Please Log in or Create an account to join the conversation.
- Jackie
- Offline
- Platinum Member
- Posts: 4787
JustCarmen wrote: Yes, Jackie I know. But I'd just answered his questions in Dutch (because he wrote to me in Dutch) when I saw his message here. If I had the time I would have translated it here but I was in a hurry, sorry.
No problem, Carmen. I know how devoted you are to webtrees. Thank you.
Please Log in or Create an account to join the conversation.
- jopla
- Topic Author
- Offline
- Junior Member
- Posts: 241
Herewith is the original _custom/theme.php. In red are the items you have to rename in my opinion if you make a copy of the _custom dir,
Please, can somebody check my comments?
<?php
namespace MyNamespace\MyProject; //change to f.e. MyThemeProject
/**
comments
*/
use Fisharebest\webtrees\Menu;
use Fisharebest\webtrees\Theme\webtreesTheme; // choose here the theme which you want to use as base for your theme.
You can find the name in the theme.php from the choosen theme. (f.e. webtreesTheme or ColorsTheme)
but I m not complete sure if I m right here.
/**
comments
*/
class MyTheme extends webtreesTheme {
//// choose here the theme which you want to use as base for your theme. You can find the name in the theme.php from the choosen theme.
//(f.e. webtreesTheme or ColorsTheme).
/**
* Give your theme a unique identifier. Themes beginning with an underscore
* are reserved for internal use.
*
* {@inheritdoc}
*/
public function themeId() {
return '_custom'; // choose here a name without "_" at start, f.f. my_theme
}
/**
* Give your theme a name. This is shown to the users.
* Use HTML entities where appropriate. e.g. “Black & white”.
*
* You could use switch($this->locale) {} to provide a translated versions
* of the theme name.
*
* {@inheritdoc}
*/
public function themeName() {
return 'Custom theme'; // f.e. Own Theme. This will be shown in the menu.
}
/**
* This is an example function which shows how to add an additional CSS file to the theme.
*
* {@inheritdoc}
*/
public function stylesheets() {
$css_files = parent::stylesheets();
// Put a version number in the URL, to prevent browsers from caching old versions.
$css_files[] = WT_BASE_URL . 'themes/_custom/custom-v1.0.css'; // choose the path of the css file for the theme
return $css_files;
}
/**
* This is an example function which shows one way to remove an entry from a menu.
*
* @param string $surname The significant surname for the page.
*
* {@inheritdoc}
*/
public function menuLists($surname) {
// Start with the default "Lists" menu.
$menu = parent::menuLists($surname);
// Remove the "notes" sub-menu.
$submenus = array_filter($menu->getSubmenus(), function (Menu $menu) {
return $menu->getClass() !== 'menu-list-note';
});
// Replace the sub-menus
$menu->setSubmenus($submenus);
return $menu;
}
}
return new MyTheme; // This script must return a theme object.
Please Log in or Create an account to join the conversation.