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

context_processors: Created basic context processor for setting base template #423

Closed
wants to merge 2 commits into from

Conversation

Arfs6
Copy link

@Arfs6 Arfs6 commented Mar 2, 2024

Inspired by the tips of django-htmx docs, I created a context processor that sets the base template to a partial template if the request is a htmx request, else to a full template.
This pull request currently has a basic implementation with some hard-coded values that will not be suitable for django-htmx.
The hard-coded values are of both the base_template variable and it's value. To eliminate this, I am going to make the function to look for both values in the settings.py file. For example:

DJANGO_HTMX_BASE_TEMPLATE = {
    "variable_name": "base_template",
    "values": {
        "full": "_base.html",
        "partial": "_partial.html"
    }
}

Any suggestions for the naming of the variable or the structure of the dictionary is welcomed.

If the variable or some of it's values doesn't exist, I will use the above as the default.

Another thing is to allow a user to override this values, perhaps by calling a function, but that can wait.
Now, I need green light to proceed. What do you think?

@adamchainz
Copy link
Owner

I’m glad that you’ve managed to follow the tip, but I don’t want to add a context processor to the package. It’s just complicating things to add, test, document, and maintain a 5 line function. Perhaps we could document making a context processor instead.

@adamchainz adamchainz closed this Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants