-1đź‘Ť
âś…
Thanks for your reply. I’ve actually managed to do it using some JS. I’ve converted the <li>
tags to <option>
here is the code:
<script type="text/javascript">
$(document).ready(function(){
$('.subnav').each(function() {
$(this).find('a').each(function() {
var $option = $('<option />');
$option.attr('value', $(this).attr('href')).html($(this).html());
$("#mobileNav").append($option);
});
});
$("#mobileNav").change(function(){
window.location.href = $(this).val();
});
});
</script>
I will try your solution now as it’s much cleaner, but the code above could be handy for someone else in the future.
Thanks again!
👤JDavies
2đź‘Ť
As you said yourself, the documentation tells you to use a custom template, which is exactly what you should do in this case.
<select>
{% show_sub_menu 1 "option_menu.html" %}
</select>
Then in “option_menu.html”:
{% for child in children %}
<option>{{ child.get_menu_title }}</option>
{% endfor %}
Note this will only show one level of sub-menu, for more, check {% if child.children %}
and if it is True
, do what you think is best in your case.
👤ojii
- [Answer]-Django 1.8 unable to match url patterns using multiple url conf files
- [Answer]-Id of created resource not in response header
- [Answer]-Django Context syntax error
Source:stackexchange.com