Opened 11 years ago

Closed 11 years ago

#625 closed enhancement (wontfix)

Custom CSS/JS list in the ini

Reported by: Tumulte Owned by:
Priority: major Milestone:
Component: programming Keywords: review
Cc: Parent Tickets:


I needed a simple way to add and order JS and CSS, so instead of having them hard coded in "base.html" I made a list in the ini that is "foreached" in the template above.

Here's how this work :

in mediagoblin.ini, I've added three sections (css_files, js_header_files, js_footer_files (and allow me to stress the importance of footer js)) :

It look like this :

files = """

the """/""" allow multiple lines statements cause I want to be able to move lines up and down easily. "file_1="/"file_N=" is error prone and comma lists are unreadable.

In tools/ I treat the data and send them as templates' context :

context['js_header_files'] = mg_globals.global_config.get('js_header_files', {})['files'].split()

And finally in "template/base.html", I display the data :

    {% for js_header_file in js_header_files %}
    {% set js_header_file  = request.staticdirect(js_header_file) %}
    <script src="{{js_header_file}}"></script>
    {% endfor %}

Smooth and easy.

Change History (1)

comment:1 by Christopher Allan Webber, 11 years ago

Resolution: wontfix
Status: newclosed

I think the right way to do this is to handle this via the templating mechanisms we have.

Right now someone could override mediagoblin/extra_head.html, though it might be ideal to make a separate one that's not theme-centric for someone to do local overrides... I dunno.

But what you've written above could almost already be added as a very easy plugin if you want it. I just added a "head" templatehook. You could add a template that hooks in here and loads templates based on the config file stuff, actually.

There's one piece missing from it though, you'd need to add something to the global context that has a list of all those templates, and there's currently no way to do that. If you're really interested in this, I can add that easily shortly.

Let me know, and I can help you get that in. But as for a general mediagoblin feature, I think this should not be a core way of functioning as we have other ways to provide this. I understand your rationale though!

Note: See TracTickets for help on using tickets.