1
1

I have created a forum module (a Python package under forum_modules) to extend OSQA. This module contains a template, which is correctly loaded by the forum.modules.module_templates_loader loader. I would like to create a template tag to be used within this template.

Is there any way to define template tags within OSQA forum modules? I would prefer not to drop files in OSQA’s templatetags package.

asked 01 Nov '10, 01:07

Kevin%20Yank's gravatar image

Kevin Yank
436111824
accept rate: 28%


Pretty easy, do it the exact same way as "normal" template tags libs, but instead of instantiating registry, import it from one of the existing template tag libs.

link

answered 01 Nov '10, 13:49

Hernani%20Cerqueira's gravatar image

Hernani Cerq... ♦♦
16.8k65975
accept rate: 52%

Thanks for the answer. Can you provide a little more detail? Where does that import statement belong? Importing registry from, say, forum.templatetags.question_list_tags sounds easy enough, but it doesn’t seem like it achieves anything unless that import statement is executed by the template parser.

(02 Nov '10, 18:57) Kevin Yank
1

Yes, just like you described. The trick here, and I forgot to mention it, sorry, is that you need to run that file before the template parser kicks in for the first time. So lets say in your module you create a file named module_tags.py or something like that, then you need to import that file from the module startup.py file, which is guaranteed to run before any template parsing. Or you can even define the tags inside the startup.py file.

(02 Nov '10, 19:49) Hernani Cerq... ♦♦

Worked beautifully, thankyou!

(04 Nov '10, 01:48) Kevin Yank

@Kevin Yank. Since you seem to have gotten this to work I was wondering if you could clarify your setup. I did this: http://meta.osqa.net/questions/5683/custom-template-filtertags, based on the discussion here, but can't get this to work.

(19 Dec '10, 16:46) rsp
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×44
×23
×6

Asked: 01 Nov '10, 01:07

Seen: 1,075 times

Last updated: 19 Dec '10, 16:46

powered by OSQA