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

Ryan Maine balrogmi at msn.com
Mon Jul 15 13:13:00 UTC 2013


Thanks! Now works perfectly!


2013/7/11 Hendrik Bunke <bunke.hendrik at gmail.com>

> --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
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130715/5dba8ad5/attachment-0001.html>


More information about the ckan-dev mailing list