[ckan-dev] Updating default main.css with an extension is not working

Hendrik Bunke bunke.hendrik at gmail.com
Thu Jul 11 09:42:28 UTC 2013


--On 2013-07-10 16:43, Ryan Maine wrote:
> Hello
> I'm unable to customize the default css appearence using a custom extension. But custom html templates in the same extension work perfectly, so I suppose the extension is succesfully installed. My extension has the following folders and files
> ckanext-ryan/ckanext/ryan/public/base/main.cssckanext-ryan/ckanext/ryan/public/base/main.min.cssckanext-ryan/ckanext/ryan/templates/index.htmlckanext-ryan/ckanext/ryan/fanstaticckanext-ryan/ckanext/ryan/plugin.pyckanext-ryan/setup.py
> New "index.html" template works perfectly replacing the default "index.html" when I reload the site, but not the same for css files
> This is my plugin.py file:
> import ckan.plugins as pclass CustomRyan(p.SingletonPlugin):    p.implements(p.IConfigurer)    def update_config(self, config):        # add template directory        p.toolkit.add_template_directory(config, 'templates')        p.toolkit.add_public_directory(config, 'public')        p.toolkit.add_resource('fanstatic', 'ckanext-castello')
> I only want to replace the default main.css or main.min.css file without modifying the core (so using an extension)
> What else do I need to do?
> Thanks and regards,Ryan

That's misunderstanding of the Jinja2 templage engine. Jinja does
not extend or overwrite CSS or other resource files. That's done
by fanstatic. Please read the docs at
http://docs.ckan.org/en/ckan-2.0/resources.html

So, simply put you'd do the following:

-   create a directory in your extension where your CSS (as well
    as other resources) reside. Let's say it's called
    'resources'.

-   write your custom CSS (actually you don't need to name it
    like the originals and you also don't have to put all styles
    of the original in it, just the ones you want to modify or
    add). Store it the above created directory. We assume it's
    called 'mycustom.css'

-   add a line to your plugin.py:
    p.toolkit.add_resource('resources', 'mycustom')
    where 'resource' is the directory with your files and
    'mycustom' the name with which you want to call it in your
    templates

-   in your template block do:
    {% resource 'mycustom/mycustom.css' %}


hope that helps
hendrik

-- 
Dr. Hendrik Bunke
http://gplus.to/hbunke
http://twitter.com/hbunke
http://www.hbxt.org




More information about the ckan-dev mailing list