Loop through a list of Tags and compare xWiki

若如初见. 提交于 2019-12-13 02:39:05

问题


I have a xwiki project with a Tag system implemented. What I am trying to do is solve this problem. When I click on a Tag I get the correct output but I want to sort the documents according to their other Tags, which means I need a way to search by multiple tags. What I have done is get a list of documents tagged with the first tag then use #foreach to look through each document for the Tags I need to show.

#set ($tag = "$!{request.get('tag')}")
#set ($list = $xwiki.tag.getDocumentsWithTag($tag))
#foreach($doc in $list)
    #set ($tags = $xwiki.tag.getTagsFromDocuments($doc))
    #foreach($tg in $tags) 
        #if($tg == 'Tutorial')
        {{html}} #displayDocumentList($doc false $blacklistedSpaces){{/html}}
         #end
    #end
 #end

The above code looks for documents that are tagged with $tag and Tutorial. Does not look very efficient but I am not looking for efficiency at this point of time, I just need it to work and the above code does not and I have no idea why.

EDIT::::

I tried a different solution. This time I get a $list and $list2 where $list are all the documents with the first tag and $list2 are the docs with the second tag. Then I compare each document's full name from one list to every document's full name in the second list. Still does not work. Here's the code,

#set ($tag = "$!{request.get('tag')}")
#set ($list = $xwiki.tag.getDocumentsWithTag($tag))
#set ($list2 = $xwiki.tag.getDocumentsWithTag('Tutorial'))
  #foreach($doc in $list)
     #foreach($doc2 in $list2)
        #if($doc.fullName == $doc2.fullname)
              $doc
        #end
    #end
  #end

EDIT 2::::

So now the #foreach loop gives me the correct output but my problem is I want to show the $doc as it would be shown if #{{html}} #displayDocumentList($doc false $blacklistedSpaces){{/html}} was valid. Is not because I think the first params is supposed to be a list and here $doc is just one document.


回答1:


So, Here is how to display your document. Once you get $doc use this line to show your document, {{display reference="$doc"/}}

Here is the link to the Display Macro



来源:https://stackoverflow.com/questions/18438357/loop-through-a-list-of-tags-and-compare-xwiki

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!