I have a list of users. And i want to display it in template:
{%- for user in listed_of_users -%}
<P>{{ user.name }}</P>
{%- endfor -%}
i want to create hyperlink link to user's profile for each user using predefined function "create_link". This function will return the hyper link for each object. So i write a function like below:
def users_list(users):
return jinja2.Markup('# '.join(map(create_link, users)) )
It will return a list like:
User1# User2# User3# User4#...
And i have hyperlink under each username.
I display it in template as a string using this syntax:
{{ users_list(listed_of_users)}}
But, I want to display each user like the format above. I tried:
{%- for user in users_list(listed_of_users) -%}
<P>{{ user }}</P>
{%- endfor -%}
However, it does not work. Can someone help me correct it? Thanks a lot!
{{ user }}
. It return a string of HTML text. With{{ user.name }}
, it return nothing. So it mean that the users_list function have changed the original list, right? – AgainstPIT Aug 10 '12 at 22:21