jowilf / starlette-admin

Fast, beautiful and extensible administrative interface framework for Starlette & FastApi applications
https://jowilf.github.io/starlette-admin/
MIT License
622 stars 60 forks source link

Enhancement: explain how to customize details view (add extra stuff at the top and/or bottom, via template fragment) #294

Open sglebs opened 1 year ago

sglebs commented 1 year ago

As a workaround for my attempt at https://github.com/jowilf/starlette-admin/issues/282 , I was thinking of customizing the details.html view of my entity. I was thinking of "showing extra stuff at the bottom".

I see https://github.com/jowilf/starlette-admin/blob/main/starlette_admin/templates/detail.html but copying/pasting the entire file just to customize a "footer" seems wrong.

If it is possible to "extend" an existing view with extra stuff at the top and/or bottom, please let me know where it says so in the documentation. Or maybe the documentation needs to be created?

If, on the other hand, there is no such feature, then I would humbly suggest that some well-know templating hooks be added, such as "pre-entity" and "post-entity", so that just this localized override can be written. Im my case, I could show the map for the entity being shown, for example (lat/long), as mentioned in issue ttps://github.com/jowilf/starlette-admin/issues/282 . Another use case I have is that the entity represents a chatbot config, and at the bottom I could have an interactive preview of the hatbox as defined. And so on.

Thanks for listening.

sglebs commented 1 year ago

Not sure if I got this right, but I guess I need to extend the existing one and, inside mine, redefine the body, call the one from which I am extending and then add my own extra stuff?

I mean:

{% extends "detail.html" %}
{% block body %}
    {{ super() }}
    {%my stuff here %}
{% endblock %}

Is that it?

sglebs commented 1 year ago

Unfortunately I can't define my own detail-form-entity.html because of https://github.com/jowilf/starlette-admin/issues/295

What I wanted to be able to do:

    admin.add_view(AssistantAdminView(model=Assistant, icon="fa fa-glasses",
                                        detail_template="detail-assistant.html"))

Unfortunately I cannot pass detail_template="detail-assistant.html" to the constructor :-(

jowilf commented 1 year ago

I see https://github.com/jowilf/starlette-admin/blob/main/starlette_admin/templates/detail.html but copying/pasting the entire file just to customize a "footer" seems wrong.

You can override the content block to add a footer

{% extends "detail.html" %}
{% block content %}
    {{ super() }}
    {# footer #}
{% endblock %}
sglebs commented 1 year ago

Overriding body was not working for me (I guess because one is not supposed to generate html content after the body markup) , but overriding content worked great, thanks!

sglebs commented 1 year ago

What are the interesting objects I can use from the template? I am looking at detail.html and I see:

Where can I find details/tips? Searching the docs...

Thanks!

hasansezertasan commented 12 months ago

Where can I find details/tips? Searching the docs...

I believe docs doesn't tell much about these, we've talked about the documentation with @jowilf. The documentation requires more explanation for a better user experience. I'd like to help about it, we can get inspired by the issues and discussion to explain what.

Or maybe add other examples. I have added an example to cover fields in #379 and planning to extend it. We can have more examples but even do, there are times that I can not remember some stuff from examples folder. We should improve the documentation.