Best practice to edit css from theme installed as addon

I want to use plonetheme.booster and change some css in it.

I installed it as an addon. The zip version is not the preferred option for me, because it does not have the slider function, due to limitations. So no TTW edit :frowning:

What is the best approach? If I change the css inside the egg and the product receives an update, I understand I would loose my modifications.

Should I copy this egg from buildout-cache to src folder and delcare it as a developer egg? I tried this, but buildout returned an error. It seems to be missing a parent folder with setup.py. I don't know if I need to use mrbob to create a theme then copy all the content from booster to it (seems dumb to me).. I found no doc on how to download an egg directly from github to my src folder, thus allowing me to develop over an existing addon.

Last question, can I create another product to have my customizations and use it side by side with the theme addon? I mean, have two theme addons applied at the same time? In this case I would like to override some of booster addons...

Thanks

Rafael

ps: I miss ploneCustom.css :frowning:

Can you use the theming control panel to copy the theme and then modify the copy?

It's true that the add-on looks at the contents of the slider-images folder but you can use the ZIP installation and modify the css manually to add whichever images you want to have appear in the slider (was just looking at that this weekend).

Hi Tim,

I tried that. But there are some issues with the zip installation. Differently from the addon, the image for the slider is a background image and is not responsive (I even added an issue in github). I thought it would not be easy to use the slider, otherwise the creators of the theme would not mention this limitations. But I will take a look at your approach.

I just cloned the product to my src directory and installed it as an development egg. I am making my modifications in main.css. It would be better to do it in a separate file, so I can update and don't have to go through all the diff thing. But I still do not know how to register these new css, but it should not be difficult.

I dont know a lot about Plone 5 internals, I know it may sound dumb what I say, but from a user perspective, there should still exist a TTW to add ccs in top of all my addon installed theme. I know this development is constantly changing, and lot of new features are being added, but I thought it would be usefull to leave my feedback anyway.

Thanks

If you look at https://caricaturesbyjoey.com it uses that theme and the big image is autocropped to fit mobile devices...

For CSS modifications, I would use the "cascading" feature of CSS, i.e. that you can "override" selected CSS definitions by appropriate placing of the overrides (inside the import and/or processing order).

This allows you to keep your changes separate from everything else. Of course, there may still be problems with updates - e.g. when the html/class scheme changes significantly; however, the danger is greatly reduced.

I believe I have read something about customizing CSS (and other theme related resources) in the Plone 5 documentation (on "plone.org"). It was a long time ago and I have not done it personally. But, maybe, you take a look at the documentation. At the time, I had the impression that it is a good documentation.

Best practice is to use the built-in theme editor if you do not want to develop your own theme - as @tkimnguyen already pointed out.

I have another solution, though: collective.localstyles - this gives you a ploneCustom.css alike back.
For a client with lots of lineage based subsites I needed a way to add subsite-local theme modifications without creating a new theme for each of them. It was mostly tweaking colors. I have created an add-on for that purpose.
It allows you to upload a localstyles.css or localstyles_css file to the server (localstyles.css has sometimes some issues with permission settings on virtual hosted subsites). It is then applied in the current folder and all subfolders from there on down the hierachy.
I wouldn't consider this best practice, but it works for this use case quite nicely.


1 Like

Hi everyone,

@tkimnguyen, very nice! But, I understand this autocrop is not an out of box theme functionality. or am I wrong? At least I did not see this behaviour neither in the zip, neither in the egg version. If not, did they use another product to have this functionally?

dieter Dieter, I have read the documentation, but it doesn't answer fully my question. My problem is where to write the code to overwrite the properties I need, installing a theme as an addon egg (not zip).

I was looking for something like child themes in wordpress. So, what I did is adding the product egg to my src/ folder, but I don't know if this is the best practice for production.

@thet, Thank you very much. I will give it a try.

I do not know "wordpress" and its "child theme" concept. However, you should be able to implement something like this with Plone 5.

The basic documentation is https://docs.plone.org/adapt-and-extend/theming/index.html

For something like a "child theme", I would create my own "theme" which depends (both with respect to the code as well as to "GenericSetup") on a parent theme (this will make available the resources from the parent scheme) and then provide the additions.

As far as I understood the documentation above, a theme is constructed from bundlles containing resources (javascript and/or CSS) and diazo rules. It is quite easy to add (in one's own theme) additional bundles (what likely is sufficient for you). In principle, bundles can also be extended; but apparently, this seems easy only for the so called "legacy bundle".

As mentioned before, it is a long time that I have read the documentation and I have not practised. I might have misunderstood things.

It should be possible to make a child theme with this approach:

  1. Make a new theme (you can do it TTW or as an 'add-on'

  2. Edit the rule file to something like this:

    <?xml version="1.0" encoding="utf-8"?>
      <xi:include href="++base++theme/rules.xml"/>
             <!-- title -->  
     	<before css:theme-children="#mainnavigation-wrapper">     
         	<div>Lets add some html for the title</div>
     	</before>
     </rules>
     
     <after theme-children="/html/head" >     
     	   <link href="++theme++thistheme/some.css" rel="stylesheet"/>
     </after>
    
  3. Add the some.css file to your new theme.

1 Like

Thanks a lot. This should be in the official docs.

This is built into the theme. Maybe 'autocrop' is the wrong term; it's the media queries that look at screen size and decide what CSS to apply for a given screen size. That is what is resizing the image sensibly for each type of screen.

@espenmn would you mind putting in a https://github.com/plone/documentation ticket or a pull request ?

... yes .... if I knew how:

Anyway: I did test this, works like this

  1. add Plone site.

  2. go to theming control panel, click on 'New theme'

  3. call it 'childtheme' or whatever.

  4. delete file 'index.html' (select it and click on the delete button'

  5. go to theming control panel and inspect barceloneta theme (or what ever theme you want to 'child theme'

  6. Clcik on manifest.cfg an copy all text below 'preview'

  7. go to your child theme's manifest.cfg and paste the text at the bottom, it should now look something like this:

    [theme]
    title = Childtheme
    description = My subclassed theme

    rules = rules.xml
    prefix = /++theme++parenttheme
    doctype =

    production-css = /++theme++parenttheme/some.css
    tinymce-content-css = /++theme++parenttheme/some.css

  8. save

  9. go to theming control panel, modify your theme and add a file my.css . Add the following to this file:

    body h1,
    body h2 {
    color: green;
    }

  10. Modify your child themes rules.xml to something like:

<?xml version="1.0" encoding="utf-8"?>
<rules xmlns="http://namespaces.plone.org/diazo"
       xmlns:css="http://namespaces.plone.org/diazo/css"
       xmlns:xhtml="http://www.w3.org/1999/xhtml"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:xi="http://www.w3.org/2001/XInclude">
      <xi:include href="/++theme++parenttheme/rules.xml"/>
	        
  		<before css:theme-children="#mainnavigation-wrapper">     
        	<div>Lets add some html for the title</div>
		</before>
	<after theme-children="/html/head" >     
		   <link href="++theme++childtheme/my.css" rel="stylesheet"/>
	</after>
</rules>
  1. go to theming control panel. Disable and enable the childtheme

IMPORTANT NOTE: your parent theme should use:

  <theme href="++theme++parenttheme/index.html"/>

IF not, you will have to use your own index.html in the child theme

1 Like