Jun Yin
Jun Yin

Reputation: 2419

CKAN extensions overwrite each other, what is the correct order?

When multiple CKAN extensions are installed, they seem to overwrite each other. e.g.ckan.plugins = pulgin1, plugin2, plugin3

If both plugin1 and plugin2 modify the look and feel(jinja tempaltes) of a page, it seems plugin1 takes precedence over plugin2. Is this always like this?

What about functionalities(functions, etc.)? Did not find the code relate to this or documentation.

Upvotes: 2

Views: 851

Answers (1)

Florian Brucker
Florian Brucker

Reputation: 10365

With regards to templates, plugins listed to the left take precedence over those listed further to the right. In your example, if all three plugins provide the same template than that of plugin1 will be used.

However, this does not mean that the template changes by the other plugins are completely lost: when implementing a template, a plugin can decide to extend the existing template using the ckan_extends syntax.

If each of the plugins in your example uses ckan_extends on the same template, then plugin3 extends CKAN's base version of that template, plugin2 extends that of plugin3, and finally plugin1 extends that of plugin2. If one of the plugins doesn't use ckan_extends then that chain is broken.

In the other cases, plugins are usually called in the order they are listed (from left to right). For example, if both plugin1 and plugin2 implement the IMiddleware interface then plugin1.make_middleware is called first and its result is passed to plugin2.make_middleware.

This also means that plugins listed to the left override those to the right when they use the same name for a resource view type, template helper, etc. See the section on avoiding name clashes in the CKAN documentation for more information.

For action functions defined via IActions, you can use the ckan.plugins.toolkit.chained_action decorator to extend existing action functions instead of replacing them (similar to template inheritance). The same holds for auth functions defined via IAuthFunctions, where you can use the ckan.plugins.toolkit.chained_auth_function decorator.

Upvotes: 5

Related Questions