inveniosoftware / flask-breadcrumbs

Flask-Breadcrumbs is a Flask extension that adds support for generating site breadcrumb navigation.
https://flask-breadcrumbs.readthedocs.io
Other
30 stars 23 forks source link

breadcrumbs: routes with variables #16

Closed snorfalorpagus closed 9 years ago

snorfalorpagus commented 9 years ago

How does Flask-Breadcrumbs handle routes with a variable? For example:

@app.route('/users/<int:user_id>')

In this instance, I'd want the breadcrumb to include a property of the user, not just the ID, e.g.:

/Users/Snorfalorpagus
jirikuncar commented 9 years ago

@snorfalorpagus please check endpoint_arguments_constructor on http://flask-breadcrumbs.readthedocs.org/en/latest/#flask.ext.breadcrumbs.register_breadcrumb.

snorfalorpagus commented 9 years ago

@jirikuncar I had not noticed these arguments. I'm new to using Flask, and some of the terminology is not familiar.

I've managed to do what I wanted using the dynamic_list_constructor keyword argument - see below. I couldn't figure out how do use endpoint_arguments_constructor. Is there an easier way I'm missing?

def func(*args, **kwargs):
    user_id = request.view_args['user_id']
    user = User.query.get(user_id)
    return [{'text': user.name, 'url': user.url}]

@main.route('/users/<int:state_id>')
@breadcrumbs.register_breadcrumb(main, '.user', '', dynamic_list_constructor=func)
def view_state(user_id):
    ...
jirikuncar commented 9 years ago

@snorfalorpagus I'm afraid I don't know any easier way. Do you have any suggestion how to make it simpler? Would you mind creating a pull-request with your example to the package documentation? Thanks

snorfalorpagus commented 9 years ago

@jirikuncar That's fine. I'll try and get a PR in sometime this week.

jirikuncar commented 9 years ago

@snorfalorpagus any progress with the PR?