Showing related content based on page labels in Viewport

345 views
Skip to first unread message

Tino Kraft

unread,
Mar 10, 2016, 6:04:44 AM3/10/16
to Scroll Viewport Developers
Hi,

does anyone know of a way to display pages in a Viewport theme that share labels with the page the user is viewing? This is a nice way of promoting content in our rather large public documentation, so I would be disappointed, if it's not possible in Viewport.

Up until now we've been using the Related Content user macro to accomplish this in our current Confluence theme: https://confluence.atlassian.com/pages/viewpage.action?spaceKey=DISC&title=Related+Content

However, with Viewport it doesn't seem to work. I added the macro to a page, which I include in our Viewport theme files by using $include.page("The Page"), which results in an error message:

Error formatting macro: contentbylabel: com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql : null

Does anyone have any experience implementing this kind of functionality in Viewport?

Regards,
Tino

Stefan Kleineikenscheidt (K15t Software)

unread,
Mar 14, 2016, 4:46:30 AM3/14/16
to scroll-vi...@googlegroups.com

Hi Tino,

right now I am not aware of a functionality to be used 'out-of-the-box', as we try to make Scroll Viewport compatible with Confluence versions before CQL was there.

Right now the only option I can think of is a pluggable placeholder: https://www.k15t.com/display/VPRT/Develop+Pluggable+Placeholders  If you are a Java developer it is not that hard.

On the other hand I have created an improvement issue to implement a "CQL" placeholder: https://k15t.jira.com/browse/VPRT-844

Cheers,
-Stefan


--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scroll-viewport-dev/666a345f-786b-409e-b93e-3d5c15526214%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tino Kraft

unread,
Mar 14, 2016, 5:37:37 AM3/14/16
to Scroll Viewport Developers
Hi Stefan,

thanks for the reply and for making a change request!

We might look into creating a pluggable placeholder. Could you give me some pointers for this specific case concerning the development of the plugin? None of us have any experience creating Confluence plugins or working with the Atlassian SDK, so any help would be appreciated (we do have people with Java experience, so this might be possible).

-Tino


On Monday, 14 March 2016 10:46:30 UTC+2, Stefan Kleineikenscheidt (K15t Software) wrote:

Hi Tino,

right now I am not aware of a functionality to be used 'out-of-the-box', as we try to make Scroll Viewport compatible with Confluence versions before CQL was there.

Right now the only option I can think of is a pluggable placeholder: https://www.k15t.com/display/VPRT/Develop+Pluggable+Placeholders  If you are a Java developer it is not that hard.

On the other hand I have created an improvement issue to implement a "CQL" placeholder: https://k15t.jira.com/browse/VPRT-844

Cheers,
-Stefan

On Thu, Mar 10, 2016 at 12:04 PM, Tino Kraft <ti...@pulse247.info> wrote:
Hi,

does anyone know of a way to display pages in a Viewport theme that share labels with the page the user is viewing? This is a nice way of promoting content in our rather large public documentation, so I would be disappointed, if it's not possible in Viewport.

Up until now we've been using the Related Content user macro to accomplish this in our current Confluence theme: https://confluence.atlassian.com/pages/viewpage.action?spaceKey=DISC&title=Related+Content

However, with Viewport it doesn't seem to work. I added the macro to a page, which I include in our Viewport theme files by using $include.page("The Page"), which results in an error message:

Error formatting macro: contentbylabel: com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql : null

Does anyone have any experience implementing this kind of functionality in Viewport?

Regards,
Tino

--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport-dev+unsub...@googlegroups.com.

Stefan Kleineikenscheidt (K15t Software)

unread,
Mar 14, 2016, 5:48:33 AM3/14/16
to scroll-vi...@googlegroups.com

Hi Tino,

This is where you would start with addon development:

Cheers,
-Stefan




On Mon, Mar 14, 2016 at 10:37 AM, Tino Kraft <ti...@pulse247.info> wrote:
Hi Stefan,

thanks for the reply and for making a change request!

We might look into creating a pluggable placeholder. Could you give me some pointers for this specific case concerning the development of the plugin? None of us have any experience creating Confluence plugins or working with the Atlassian SDK, so any help would be appreciated (we do have people with Java experience, so this might be possible).

-Tino

On Monday, 14 March 2016 10:46:30 UTC+2, Stefan Kleineikenscheidt (K15t Software) wrote:

Hi Tino,

right now I am not aware of a functionality to be used 'out-of-the-box', as we try to make Scroll Viewport compatible with Confluence versions before CQL was there.

Right now the only option I can think of is a pluggable placeholder: https://www.k15t.com/display/VPRT/Develop+Pluggable+Placeholders  If you are a Java developer it is not that hard.

On the other hand I have created an improvement issue to implement a "CQL" placeholder: https://k15t.jira.com/browse/VPRT-844

Cheers,
-Stefan

On Thu, Mar 10, 2016 at 12:04 PM, Tino Kraft <ti...@pulse247.info> wrote:
Hi,

does anyone know of a way to display pages in a Viewport theme that share labels with the page the user is viewing? This is a nice way of promoting content in our rather large public documentation, so I would be disappointed, if it's not possible in Viewport.

Up until now we've been using the Related Content user macro to accomplish this in our current Confluence theme: https://confluence.atlassian.com/pages/viewpage.action?spaceKey=DISC&title=Related+Content

However, with Viewport it doesn't seem to work. I added the macro to a page, which I include in our Viewport theme files by using $include.page("The Page"), which results in an error message:

Error formatting macro: contentbylabel: com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql : null

Does anyone have any experience implementing this kind of functionality in Viewport?

Regards,
Tino

--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scroll-viewport-dev/3fe1a576-996b-40fb-b17e-4acdf1307cf7%40googlegroups.com.

Michal Krejčí

unread,
Jul 22, 2019, 8:34:21 AM7/22/19
to Scroll Viewport Developers
Hello Tino,

I wonder if you have ever managed to find a solution or perhaps created a plugin of some sort to achieve the aforementioned requirement?

Sharon Metzger

unread,
Jul 22, 2019, 9:04:31 AM7/22/19
to scroll-vi...@googlegroups.com
I wasn’t on this list when this thread started, but I use the Content by Label macro and it works fine in Viewport — shows a list of pages with the labels you specify in the macro.


Sharon

On Jul 22, 2019, at 8:34 AM, 'Michal Krejčí' via Scroll Viewport Developers <scroll-vi...@googlegroups.com> wrote:

Hello Tino,

I wonder if you have ever managed to find a solution or perhaps created a plugin of some sort to achieve the aforementioned requirement?

--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scroll-viewport-dev/f373c984-c7b0-4279-abe8-d2669e2b74a6%40googlegroups.com.

Michal Krejčí

unread,
Jul 22, 2019, 9:24:27 AM7/22/19
to Scroll Viewport Developers
Thank you for the tip, but I am unfortunately looking for displaying the content of pages, not just a list of them.


Dne pondělí 22. července 2019 15:04:31 UTC+2 Sharon Metzger napsal(a):

Sharon Metzger

unread,
Jul 22, 2019, 9:27:53 AM7/22/19
to scroll-vi...@googlegroups.com
Ah, I see. The “Content by Label” macro has an option to display excerpts for each page in the list. Maybe that option is worth investigating? I haven’t experimented with it.

Sharon

Luke Johnson

unread,
Aug 23, 2019, 11:19:23 PM8/23/19
to Scroll Viewport Developers
Hey Sharon - how did you render the content by label macro within a viewport vm file?

I cannot see where in the documentation it talks about rendering a macro?

Sharon Metzger

unread,
Aug 27, 2019, 3:55:47 PM8/27/19
to scroll-vi...@googlegroups.com
Hi Luke —

I don’t think I did anything special to handle the macro. It’s a confluence macro to generate the content of the list (link or link+excerpt), and Viewport handles it like any other content.

Sharon

--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.

Dan Taube

unread,
Mar 14, 2020, 7:33:55 PM3/14/20
to Scroll Viewport Developers
Luke,

You asked this a good while ago, but thought I would share how you can go about this.

First, I believe Sharon is saying that the Content by Label macro was used in a page and then that page rendered it without issue in the viewport. Rather than call it specifically.

Now, you are actually able to call a similar function with a viewport provided placeholder: getContentByLabel(label). With that, you can have your template file handle it with a foreach argument.

Example (pinnedpages.vm):
#set($pinnedPages = $repository.getContentByLabel("pinned"))

#foreach($page in $pinnedPages)
 
<a href="$page.link">$page.title</a>
 <p class="card-text">$page.excerpt</
p>
 
<p class="card-text">$page.lastModificationDate("MMMM dd, YYYY")</p>
#end

Dan

Amit Kapoor

unread,
May 12, 2020, 7:38:07 PM5/12/20
to Scroll Viewport Developers
Hi Dan,

Thanks! How would this code change if for each label on the current page, I want to list the first three pages from the list of pages that have the same label?

-Amit

Amit Kapoor

unread,
May 12, 2020, 8:56:42 PM5/12/20
to Scroll Viewport Developers
Hi Dan,

I could do some on my own and it works. I wonder how  limit the loop to predefined number of times. The code:

#foreach($label in $page.labels)
 
#set($pinnedPages = $repository.getContentByLabel("$!label"))
 
#set($currentpage = $page)
   
#foreach($page in $pinnedPages)
     
#if($page != $currentpage)

     
       
<a href="$page.link">$page.title</a>

     
     
#end
   
#end
#end


Message has been deleted

Amit Kapoor

unread,
May 12, 2020, 9:34:43 PM5/12/20
to Scroll Viewport Developers

It is done. Thanks Dave for the initial code. I have set the number of pages to be listed using count to 2.

<div class="relatedtopics">

#foreach($label in $page.labels)
  #set($pinnedPages = $repository.getContentByLabel("$!label"))
  #set($currentpage = $page)
  #set($count = 1)
    #foreach($page in $pinnedPages)
      #if(($page != $currentpage) && ($count < 3))
     
<li>
       
<ul><a href="$page.link">$page.title</a></ul>
     
</li>
      #set($count = $count + 1)
      #end
    #end
#end
</div>


Dan T

unread,
May 19, 2020, 7:27:54 PM5/19/20
to Scroll Viewport Developers
Nice work, Amit!

Amit Kapoor

unread,
May 22, 2020, 12:11:15 PM5/22/20
to Scroll Viewport Developers

Thanks Dan.

Now, I am thinking of enhancing it. I want to list the first five pages that share the maximum number of labels with the current page's labels. For practical situation, I will assume that a page usually has only 5 labels. So pages with same 5 labels should be listed first, followed by pages with 4/5 of these labels, then 3/5, and so on but only 5 pages in total. If you or anyone can help, it will be great. I plan to work on this soon...I will share whatever I get done here.


Dan Taube

unread,
May 22, 2020, 3:33:41 PM5/22/20
to scroll-vi...@googlegroups.com
So, I think I can get you on the right path. I had to do similar to sort by the creation date. In short, you have to loop through the pages object you get and then build a new one with an additional element that has the count. Then you can use the sort function that Viewport has. 

When I'm back at the computer I'll share it with you. 

Dan

On Fri, May 22, 2020, 11:11 AM Amit Kapoor <amitdo...@gmail.com> wrote:

Thanks Dan.

Now, I am thinking of enhancing it. I want to list the first five pages that share the maximum number of labels with the current page's labels. For practical situation, I will assume that a page usually has only 5 labels. So pages with same 5 labels should be listed first, followed by pages with 4/5 of these labels, then 3/5, and so on but only 5 pages in total. If you or anyone can help, it will be great. I plan to work on this soon...I will share whatever I get done here.


--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.

Amit Kapoor

unread,
May 27, 2020, 4:53:52 AM5/27/20
to Scroll Viewport Developers

Thanks Dave! I will wait for it. You are savior!

Amit Kapoor

unread,
Jun 6, 2020, 9:20:45 PM6/6/20
to Scroll Viewport Developers

Hi Dave!

Do you think you will be able to share the code soon?

Thank you.

-Amit

Amit Kapoor

unread,
Jun 19, 2020, 5:18:30 AM6/19/20
to Scroll Viewport Developers
Incorrect list format..

Fixed below:

<div class="relatedtopics">
<ul>

#foreach($label in $page.labels)
  #set($pinnedPages = $repository.getContentByLabel(
"$!label"))
  #set($currentpage = $page)
  #set($count = 1)
    #foreach($page in $pinnedPages)
      #if(($page != $currentpage) && ($count < 3))
     
<li>

       
<a href="$page.link">$page.title</a>

     
</li>

      #set($count = $count + 1)
      #end
    #end
#end
</ul>
</div>


amitdo...@gmail.com

unread,
Aug 26, 2020, 4:36:45 AM8/26/20
to Scroll Viewport Developers
@Dave ?
Reply all
Reply to author
Forward
0 new messages