Skip to content

Conversation

@seitenbau-govdata
Copy link
Member

During our last fix for including the root_path (#144), we encountered a problem when another language is used with CKAN. When a language is explicitely set in the url, the generated links by the pages plugin did not contain the language using our previous fix.

This fix uses the "internal" _local_url to generate the links (in my oppinion this should be a public helper function, providet by the toolkit for plugins) and thus the links will be generated with the same code CKAN uses internally. This should make the generated link robust and should always follow CKANs configuration.

@bluepython508
Copy link

We've been using a somewhat different patch to do the same thing, which may be somewhat better, since it doesn't rely on CKAN internals.

diff --git a/ckanext/pages/plugin.py b/ckanext/pages/plugin.py
index 37a4fc5..105fbc7 100644
--- a/ckanext/pages/plugin.py
+++ b/ckanext/pages/plugin.py
@@ -64,10 +64,10 @@ def build_pages_nav_main(*args):
         page_name = tk.request.path.split('/')[-1]

     for page in pages_list:
-        type_ = 'blog' if page['page_type'] == 'blog' else 'pages'
+        endpoint = 'pages.blog_show' if page['page_type'] == 'blog' else 'pages.show'
         name = quote(page['name'])
         title = html_escape(page['title'])
-        link = tk.h.literal(u'<a href="{}/{}/{}">{}</a>'.format(root_path, type_, name, title))
+        link = tk.h.literal(u'<a href="{}">{}</a>'.format(tk.h.url_for(endpoint, page=name), title))
         if page['name'] == page_name:
             li = tk.literal('<li class="active">') + link + tk.literal('</li>')
         else:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants