0

I would like to pass an array in django

{% include '/blocks/block-products-carousel.html' with
        groups= [
            {title: 'All', active: true},
            {title: 'Power Tools', active: false},
            {title: 'Hand Tools', active: false},
            {title: 'Plumbing', active: false},
        ],
  • Can you be more specific? Check this question if it's somewhat similar to your requirement https://stackoverflow.com/questions/739942/how-to-pass-an-array-in-django-to-a-template-and-use-it-with-javascript – Chandragupta Borkotoky Jun 08 '21 at 04:32

1 Answers1

1

Can you create the array (list) in the view code and pass it to the context like this

 def view(request)
     groups_list = [
        {title: 'All', active: true},
        {title: 'Power Tools', active: false},
        {title: 'Hand Tools', active: false},
        {title: 'Plumbing', active: false},
    ]
     render (request,"template.html",{"groups_list":groups_list})

then in your template

 {% include '/blocks/block-products-carousel.html' with groups=groups_list %}
Mohamed ElKalioby
  • 1,908
  • 1
  • 12
  • 13