How to add custom menu items under just above the footer link

Hi Gurus,

I have another quest to add new menu items in the footer section of the indico.
How to add custom menu items under just above the footer link.?
image
Thank you so much.

You can do this in your plugin as well.

Add this to the init() method:

self.template_hook('page-footer', self._inject_footer_links)

and then add this method in the plugin’s class itself:

    def _inject_footer_links(self, **kwargs):
        return '''
            put HTML to insert in the footer here
        '''

The value returned there will be included as list entries after the existing footer links. You cannot easily insert links before them.

To add e.g. a link to your site, you’d add this:

<a href="https://example.com">My site</a>

In case you want multiple links nicely separated, use this:

    def _inject_footer_links(self, **kwargs):
        yield '''
            put HTML to insert in the footer here
        '''
        yield '''
            put another HTML snipped here
        '''

you can yield as many strings as you want; each will become one item there.

Note: In principle it would be much cleaner to use a template file for this, but since your plugin just uses a single file this is faster and saves me some time explaining how to turn your plugin into a package that can include template files etc. and for a small custom plugin this is perfectly fine anyway :wink:

1 Like

Thanks so much. It works nicely.

    def _inject_footer_links(self, **kwargs):
        return ('<a href=\'#\'>aaa</a> | <a href=\'#\'>bbb</a> | <a href=\'#\'>aaa</a> | <a href=\'#\'>ccc</a>')

You can make this much more readable and let Indico handle the item separators for you :wink:

    def _inject_footer_links(self, **kwargs):
        yield '<a href="#">aaa</a>'
        yield '<a href="#">bbb</a>'
        yield '<a href="#">ccc</a>'
1 Like

tried with but not showing/working. with return it works

    def _inject_footer_links(self, **kwargs):
        yield '<a href="#">aaa</a>'
        yield '<a href="#">bbb</a>'
        yield '<a href="#">ccc</a>'

should I have escaped " with \" ?

no, you only need to escape the quote that are used outside (and triple quoted string are multiline and allow both).

anyway, i just realized that this is a template hook and template hooks don’t seem to support yielding, so the proper way of showing multiple items is this:

    def _inject_footer_links(self, **kwargs):
        return '''
            <a href="#">aaa</a></li>
            <li><a href="#">bbb</a></li>
            <li><a href="#">ccc</a>
        '''
1 Like

i added unicode text in Mongolian in the menu items then got following error:

[root@localhost ~]# tail /tmp/uwsgi.log
    reraise(*rewrite_traceback_stack(source=source))
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/web/templates/footer.html", line 2, in top-level template code
    {% block footer -%}
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/web/templates/footer.html", line 29, in block "footer"
    {% for item in template_hook('page-footer', as_list=true) %}
  File "/opt/indico/.venv/lib/python2.7/site-packages/indico/web/flask/templating.py", line 194, in call_template_hook
    value = Markup(value)
  File "/opt/indico/.venv/lib/python2.7/site-packages/markupsafe/__init__.py", line 74, in __new__
    return text_type.__new__(cls, base)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 46: ordinal not in range(128)
[root@localhost ~]#

Add from __future__ import unicode_literals to the top of the file

1 Like

it works now but words are broken

image

Make sure the file is saved as UTF-8. Also try adding a line # encoding=utf-8 at the very top of the file.

1 Like

Yes this solved the issue.

I tried changing default language of indico installation on my Production server by editing vi /opt/indico/etc/indico.conf and changing DEFAULT_LOCALE = 'mn_MN' and restarted all the services with systemctl restart uwsgi.service httpd.service indico-celery.service but it has no effect.

Sorry off the topic question could not find any reference by searching in the forum.

Try in an incognito tab. But even in that case it depends on the preferred language your browser sends.
The default language for a logged-in user is stored for that user so they need to change it manually.

So the default language is only used if there is neither a language stored for a user nor a preference sent by the browser.

1 Like

In incognito tab it is same. It shows English page.

What does https://httpbin.org/headers show as the “Accept-Language” header your browser sends?

{
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", 
    "Accept-Encoding": "gzip, deflate, br", 
    "Accept-Language": "en-US,en;q=0.9", 
    "Host": "httpbin.org", 
    "Referer": "https://talk.getindico.io/", 
    "Sec-Ch-Ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"", 
    "Sec-Ch-Ua-Mobile": "?0", 
    "Sec-Fetch-Dest": "document", 
    "Sec-Fetch-Mode": "navigate", 
    "Sec-Fetch-Site": "cross-site", 
    "Sec-Fetch-User": "?1", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", 
    "X-Amzn-Trace-Id": "Root=1-608d7c19-2bb28ea12319bb722621647f"
  }
}

in incognito tab

{
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", 
    "Accept-Encoding": "gzip, deflate, br", 
    "Accept-Language": "en-US,en;q=0.9", 
    "Host": "httpbin.org", 
    "Sec-Ch-Ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"", 
    "Sec-Ch-Ua-Mobile": "?0", 
    "Sec-Fetch-Dest": "document", 
    "Sec-Fetch-Mode": "navigate", 
    "Sec-Fetch-Site": "none", 
    "Sec-Fetch-User": "?1", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36", 
    "X-Amzn-Trace-Id": "Root=1-608d7c4d-3775aec24746225f67e7da8c"
  }
}

There we go. Your browser tells websites that it prefers english. Check your browser settings; there’s usually an option to set the preferred website languages.

1 Like

I was wondering if the help item be removed from the footer permanently. I wanted to move it to within contact page.

I tried deleting the list item from footer.html, but the output page still shows help item.

<li>
                    <a href="{{ indico_config.HELP_URL }}">
                        {% trans %}Help{% endtrans %}
                    </a>
                </li>

On a side note, thank you for this wonderful project. I was always procrastinating when it came to learning python. But started learning it with interest after exploring Indico.