遍历标签列表并比较 xWiki [英] Loop through a list of Tags and compare xWiki

查看:28
本文介绍了遍历标签列表并比较 xWiki的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实施了标签系统的 xwiki 项目.我想做的是解决 这个 问题.当我点击一个标签时,我得到了正确的输出,但我想根据其他标签对文档进行排序,这意味着我需要一种通过多个标签进行搜索的方法.我所做的是获取用第一个标签标记的文档列表,然后使用 #foreach 查看每个文档以查找我需要显示的标签.

#set ($tag = "$!{request.get('tag')}")#set ($list = $xwiki.tag.getDocumentsWithTag($tag))#foreach($list 中的 $doc)#set ($tags = $xwiki.tag.getTagsFromDocuments($doc))#foreach($tg 在 $tags)#if($tg == '教程'){{html}} #displayDocumentList($doc false $blacklistedSpaces){{/html}}#结尾#结尾#结尾

以上代码查找带有$tagTutorial 标签的文档.看起来效率不高,但此时我不是在寻求效率,我只是需要它工作,而上面的代码却没有,我也不知道为什么.

:::

我尝试了不同的解决方案.这次我得到一个 $list$list2 其中 $list 是所有带有第一个标签和 $list2 的文档code> 是带有第二个标签的文档.然后我将一个列表中每个文档的全名与第二个列表中每个文档的全名进行比较.仍然不起作用.这是代码,

#set ($tag = "$!{request.get('tag')}")#set ($list = $xwiki.tag.getDocumentsWithTag($tag))#set ($list2 = $xwiki.tag.getDocumentsWithTag('教程'))#foreach($list 中的 $doc)#foreach($list2 中的 $doc2)#if($doc.fullName == $doc2.fullname)$doc#结尾#结尾#结尾

编辑 2::::

所以现在 #foreach 循环给了我正确的输出,但我的问题是我想显示 $doc,如果 #{{html}} #displayDocumentList($doc false $blacklistedSpaces){{/html}} 有效.不是因为我认为第一个参数应该是一个列表,而这里 $doc 只是一个文档.

解决方案

所以,这里是如何显示您的文档.获得 $doc 后,使用此行显示您的文档,{{display reference="$doc"/}}

这是显示宏的链接

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.

解决方案

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

这篇关于遍历标签列表并比较 xWiki的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆