Show Tag Count

23 views
Skip to first unread message

KuoYing@Taiwan

unread,
Jan 23, 2011, 4:41:12 AM1/23/11
to play-framework
Hi all:
In main.html file I want to show "itemTag" data, so I using...

>>
#{list allTags}
<div class="content_left_kind_list"
id="KDlist01">#{main.itemTag name:_.tagName /}(0)</div>
#{/list}
>>

It looks better, and allTags is query Tag class.....but my question is
"(0)"..I want to show how many items in the Tag...It will try to query
Item class..for example: Item.find("byItemTag",
_.tagNam ).fetch().size();

But this query string could replace "(0)"................

Nicolas Martignole

unread,
Jan 23, 2011, 5:15:15 AM1/23/11
to play-fr...@googlegroups.com
Please read the documentation about the list tag

http://www.playframework.org/documentation/1.1/tags#list

#{list allTags, as:'currentTag'}
  <div class="content_left_kind_list" id="KDlist_${currentTag_index}">
    ${currentTag_index} ${currentTag.name}
  </div>
#{/list}

Nicolas

2011/1/23 KuoYing@Taiwan <stu93...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


KuoYing@Taiwan

unread,
Jan 23, 2011, 10:35:45 AM1/23/11
to play-framework
Hi..
I try to do this:
-------------------------
#{list items:models.Item.find('byItemTag', _name).fetch(), as:'tag'}
${tag.size()}
#{/list}
------------------------
But it can't shows size number. But when only #{tag} it is OK, but not
I want..I want size() number!!


On 1月23日, 下午6時15分, Nicolas Martignole <nico...@martignole.net> wrote:
> Please read the documentation about the list tag
>
> http://www.playframework.org/documentation/1.1/tags#list
>
> #{list allTags, as:'currentTag'}
>   <div class="content_left_kind_list" id="KDlist_${currentTag_index}">
>     ${currentTag_index} ${currentTag.name}
>   </div>
> #{/list}
>
> Nicolas
>
> 2011/1/23 KuoYing@Taiwan <stu93303...@gmail.com>
>
>
>
>
>
>
>
> > Hi all:
> > In main.html file I want to show "itemTag" data, so I using...
>
> > #{list allTags}
> >                <div class="content_left_kind_list"
> > id="KDlist01">#{main.itemTag name:_.tagName /}(0)</div>
> > #{/list}
>
> > It looks better, and allTags is query Tag class.....but my question is
> > "(0)"..I want to show how many items in the Tag...It will try to query
> > Item class..for example: Item.find("byItemTag",
> > _.tagNam ).fetch().size();
>
> > But this query string could replace "(0)"................
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "play-framework" group.
> > To post to this group, send email to play-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > play-framewor...@googlegroups.com<play-framework%2Bunsubscribe@go oglegroups.com>
> > .

David Wursteisen

unread,
Jan 23, 2011, 10:57:23 AM1/23/11
to play-fr...@googlegroups.com
#{list items:models.Item.find('byItemTag', _name).fetch(), as:'tag'}

I don't think that a view is a good place to do a database query. 

I suggest you to do your query in your controller, then render your view with your list : 

// in your controller
public static void myView() {
        List myList = models.Item.find('byItemTag', _name).fetch();     

        render(myList);

}



// in your view  (ie : myView.html)
list size = ${myList.size()}
iterate over my list : 
#{list items:myList, as:'tag'}
     a tag ==> ${tag}
#{/list}
2011/1/23 KuoYing@Taiwan <stu93...@gmail.com>
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

KuoYing@Taiwan

unread,
Jan 23, 2011, 11:48:40 AM1/23/11
to play-framework
But this tag is on the main.html Template >"< how to query in my
controller??

On 1月23日, 下午11時57分, David Wursteisen <david.wurstei...@gmail.com>
wrote:
> #{list items:models.Item.find('byItemTag', _name).fetch(), as:'tag'}
>
> I don't think that a view is a good place to do a database query.
>
> I suggest you to do your query in your controller, then render your view
> with your list :
>
> // in your controller
> public static void myView() {
>         List myList = models.Item.find('byItemTag', _name).fetch();
>
>         render(myList);
>
> }
>
> // in your view  (ie : myView.html)
> list size = ${myList.size()}
> iterate over my list :
> #{list items:myList, as:'tag'}
>      a tag ==> ${tag}
> #{/list}
> 2011/1/23 KuoYing@Taiwan <stu93303...@gmail.com>

Marcus Downing

unread,
Jan 28, 2011, 5:14:12 AM1/28/11
to play-fr...@googlegroups.com
You mean it's on every page that uses main.html, and you need to do the query on all of them? I believe you should add a method to your controller like this:
@Before static void fetchList() {
List myList = models.Item.find('byItemTag', _name).fetch();
renderArgs.put('myList', myList);
}

This will get run for every action in your controller, and the myList variable will be available in all the views. David is right, you shouldn't do database queries in the view.
Reply all
Reply to author
Forward
0 new messages