Re: Template syntax question
I like the suggestions, Thanks! On Oct 28, 12:47 am, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On Oct 27, 10:04 pm, Robocop <[EMAIL PROTECTED]> wrote: > > > So i'm looking to have an admin controlled news list, and one thing in > > particular i'd like them to be able to control is how many headlines > > are shown on the front page, and my current code is not doing that. > > > The line i care about is: > > > {% for New in news_list|slice:":{{limit}}"%} > > > where limit is some admin controlled variable that i'm certain is an > > integer. Is this possible? Or is there just some error in my code > > somewhere that i have not seen? Thanks! > > You can't nest tags like that. > > There are various options - have you tried defining a string in your > view which is ":" + limit, and passing that to thetemplate? Or > perhaps limiting news_list in your view? > > Or, you could define a custom filter which takes a value and returns a > list sliced to that length. Something like (untested): > def slice_to_var(lst, lngth): > return lst[:lngth] > -- > DR. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Template syntax question
On Oct 27, 10:04 pm, Robocop <[EMAIL PROTECTED]> wrote: > So i'm looking to have an admin controlled news list, and one thing in > particular i'd like them to be able to control is how many headlines > are shown on the front page, and my current code is not doing that. > > The line i care about is: > > {% for New in news_list|slice:":{{limit}}"%} > > where limit is some admin controlled variable that i'm certain is an > integer. Is this possible? Or is there just some error in my code > somewhere that i have not seen? Thanks! You can't nest tags like that. There are various options - have you tried defining a string in your view which is ":" + limit, and passing that to the template? Or perhaps limiting news_list in your view? Or, you could define a custom filter which takes a value and returns a list sliced to that length. Something like (untested): def slice_to_var(lst, lngth): return lst[:lngth] -- DR. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Template syntax question
So i'm looking to have an admin controlled news list, and one thing in particular i'd like them to be able to control is how many headlines are shown on the front page, and my current code is not doing that. The line i care about is: {% for New in news_list|slice:":{{limit}}"%} where limit is some admin controlled variable that i'm certain is an integer. Is this possible? Or is there just some error in my code somewhere that i have not seen? Thanks! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Simple Template Syntax Question: ljust
> I've tried... > > {{product.title | ljust 40}} > > and other formats but can't get it to work... You can use the slice filter: {{product.title | slice:":40" }} or if you what the to truncate only at workbrakes, you can use the truncatewaords filter: {{product.title | truncate:"5" }} Martin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Simple Template Syntax Question: ljust
It should be {{ product.title|ljust:"40" }} --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Simple Template Syntax Question: ljust
Can someone show me how to get x number of chars from a variable in a template please... I've tried... {{product.title | ljust 40}} and other formats but can't get it to work... thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---