christianwgd / django-bootstrap-icons

A quick way to add Bootstrap Icons with Django template tags.
MIT License
24 stars 7 forks source link

Not working #22

Closed zangetsu05 closed 9 months ago

zangetsu05 commented 10 months ago

Tried to use this module with the latest version, 0.8.7, followed the instruction on the pypy page(https://pypi.org/project/django-bootstrap-icons/):

Recived this error: Invalid block tag on line 9: 'bs_icon', expected 'endblock'. Did you forget to register or load this tag?

image
christianwgd commented 10 months ago

I checked the code and did not find any error. The tests are running fine and I'm using the library in several projects, which also show no errors. Can you provide your template code? Or check, if there are any typos? And maybe have a look at the sample app in the repo. Thanks.

christianwgd commented 9 months ago

Hey zangetsu05, any update on this? Otherwise I would close the issue...

christianwgd commented 9 months ago

Closing this due to inactivity. If needed, please reopen

iibarbari commented 3 days ago

Initially, I added {% load bootstrap_icons %} in my layout.html, assuming it would work globally. However, I came across the same issue. What worked for me was loading it directly in the template file where I was using the icons.

I tried two alternatives to avoid importing it in every template:

TEMPLATES = [
    {
        ...,
        'OPTIONS': {
            ...,
            'libraries': {
                'django_bootstrap_icons': 'django_bootstrap_icons',
            }
        },
    },
]

and

TEMPLATES = [
    {
        ...,
        'OPTIONS': {
            ...,
            'builtins': ['django_bootstrap_icons'],
        },
    },
]

Unfortunately, none of these options worked. We still have to manually load the template tag in every file where the icons are used.

christianwgd commented 3 days ago

Seems like a misunderstanding: You tried to set the library into the "TEMPLATES" option, but there's no setting for TEMPLATES, only for INSTALLED_APPS. Please try to compare with the sample app.

christianwgd commented 3 days ago

If you like to inherit the library, there's nothing special with this library. Please refer to for example https://stackoverflow.com/questions/1184983/load-a-django-template-tag-library-for-all-views-by-default. Seems like the libraries path is not complete. Guess it should be a relative addressing with dots, but didn't do that until now.

christianwgd commented 3 days ago

Because I was curious, I've just tried that, it's:

'builtins': [ 'django_bootstrap_icons.templatetags.bootstrap_icons' ],

(see also https://docs.djangoproject.com/en/5.1/topics/templates/#module-django.template.backends.django although this was not really complete, better look at https://medium.com/@altafkhan_24475/a-quick-guide-to-django-templates-settings-8e67419e515c)

Even after 16 Years of Django you can learn something new, thanks for that!

iibarbari commented 1 day ago

Cool, I just tried adding it to the builtins like you mentioned, and it works great. It's a cleaner approach, especially since I often use this in my templates. Thanks for digging into this 💐