Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sglebs opened this issue Sep 4, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@sglebs
Copy link

sglebs commented Sep 4, 2023

As a workaround for my attempt at #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//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 sglebs added the enhancement New feature or request label Sep 4, 2023
@sglebs
Copy link
Author

sglebs commented Sep 4, 2023

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
Copy link
Author

sglebs commented Sep 4, 2023

Unfortunately I can't define my own detail-form-entity.html because of #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
Copy link
Owner

jowilf commented Sep 5, 2023

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
Copy link
Author

sglebs commented Sep 5, 2023

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
Copy link
Author

sglebs commented Sep 5, 2023

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

  • model. This seems to be the ModelView, so I can do model.fields etc
  • obj: This seems to be the actual object being inspected, so I can do obj["filedName"]

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

Thanks!

@hasansezertasan
Copy link
Contributor

hasansezertasan commented Nov 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants