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

Feature request: Transparently pass request object to components if present #45

Open
mixxorz opened this issue Jul 28, 2023 · 6 comments

Comments

@mixxorz
Copy link
Owner

mixxorz commented Jul 28, 2023

I'm considering passing the request object from the parent context to the component transparently if it's available. My reasoning is that a bunch of existing template tags require the request object to function.

Thoughts?

@mixxorz mixxorz changed the title Feature request: Pass request object to components if present Feature request: Transparently pass request object to components if present Jul 28, 2023
@Thutmose3
Copy link

Thutmose3 commented Aug 2, 2023

Yes please! And if possible add a flag in settings, that will allow passing all context from the parent component to the component? So people can choose if they want to have parent context passing or not.

@jansonsiy-yeoki
Copy link

jansonsiy-yeoki commented Aug 2, 2023

Yes please! And if possible add a flag in settings, that will allow passing all context from the parent component to the component? So people can choose if they want to have parent context passing or not.

that would be nice, I'm passing long arguments in my components now and it becomes ugly.

example:
{% header_title_component object=event tab_name=agenda.name title=agenda.title date=agenda.date %}

@luanfonceca
Copy link

luanfonceca commented Aug 11, 2023

I would love that, I'm grinding my brain to find a workaround on a related problem, as I'm running slippers with htmx for a couple months, we're now struggling on passing many parameters and using them.

Right now this is the the Button component we have (with lots of improvements like using the match to theme the button etc):

{% comment %}
    * Parameters *
    id
    hx-get
    hx-post
    hx-delete
    hx-put
    hx-target
    hx-swap
    hx-push-url
    hx-indicator
    hx-include
    class
    onclick
    disabled
    text: string
{% endcomment %}
{% var class=class|default:"flex justify-center w-full sm:w-fit inline-flex items-center px-3 py-1.5 border border-transparent text-sm leading-4 font-medium rounded-md text-indigo-700 bg-indigo-100 hover:bg-indigo-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:bg-gray-200 disabled:text-gray-400" %}
<button {% attrs id hx-get hx-post hx-delete hx-put hx-target hx-swap hx-push-url hx-indicator hx-include disabled class onclick %} type="button">
    {{ text }}
</button>
# usage
{% Button
    text="Discard"
    onclick=toggle_discard_modal_fn
    hx-delete=discard_suggestion_url
    hx-swap="outerHTML swap:0.5s"
    hx-target="#"|concat:card_id
    hx-include="#"|concat:form_id
%}

I'm trying to find something like {% attrs **kwargs %} to kinda implement the {...props} destructing from react, any ideas?

Overall I like the idea behind #51 to pass along the children parameters and also in this case the request (maybe even extrapolate this to all available variables in that template - not sure the impact on Django' template variable resolution)

@Thutmose3
Copy link

Yeah, we are also using it together with HTMX, it's indeed cumbersome

g-nie pushed a commit to g-nie/slippers that referenced this issue Apr 23, 2024
g-nie pushed a commit to g-nie/slippers that referenced this issue Apr 23, 2024
g-nie added a commit to g-nie/slippers that referenced this issue Apr 23, 2024
@g-nie
Copy link

g-nie commented Apr 23, 2024

I opened a PR for this: #64
I am only passing the request if it's present, not the whole context, because I like that the context is sort of isolated at the component level. On the other hand, I find what @luanfonceca suggests for the {% attrs **kwargs %} quite useful, so I could look at that separately too.

@fabiocaccamo
Copy link

Any update about this feature?

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

No branches or pull requests

6 participants