On 12/5/06, matthew <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> Looking at the documentation, I see that you can do "include
> template_name" or "include 'template.html'". I'd like to combine these
> - concatenating a couple of strings and a variable to make the template
> name - but it's not working (no error, but no template included).
>
> This template displays a survey. Each survey question has a 'type'
> attribute with several choices defined in the model
> ("multiplechoice","matrix","ranking" etc).
>
> I'd like to loop through the list of questions and render each question
> using the appropriate template, which is determined by the type of
> question. So for example a 'multiplechoice' question corresponds to the
> 'questions/multiplechoice.html' template.
>
> This is the bit that's not working (viewsurvey.html):
> {% for question in questions %}
>     {% include 'questions/' + question.get_type_display() + '.html' %}
> {% endfor %}
>
> Why can't I concatenate the strings and variable to include the
> relevant template?
>
> The model looks like this:
> class Question(models.Model):
>      Types = ((0,"TrueFalse"),
>              (1,"MultipleChoice"))
>      type = models.IntegerField(choices=Types)
>
>
I'v write some custom tags you can try:

expr http://code.djangoproject.com/wiki/ExprTag

then the sample code is:

{% for question in questions %}
    {% expr 'questions/' + question.get_type_display() + '.html' as tmp %}
    {% include tmp %}
{% endfor %}

But I don't know if it can do the work, but you can try it.

You should save ExprTag code into some templatetags file, and use load
tag to import it. See the template_python document to get the details.

-- 
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to