arraysize: 0


Load more widget with Semantic MediaWiki

An example of using #cr-parse-request with the load more widget (#cr-load-more) to fetch further results from a Semantic MediaWiki query.

The wiki code:

{{#cr-parse-request:<nowiki>{{#ask: [[Concept:Bibliography of early Irish law]] [[Creation date::+]]
|link=none
|format=plainlist
|template=C/s
|sep=<br>
|limit={{{$limit|25}}}
|offset={{{$offset|0}}}
|searchlabel=
}}<!--
-->{{#cr-load-more:
|id=cr-load-more
|class=btn btn-dark mt-3
|text=Load more results...
|total={{#ask: [[Concept:Bibliography of early Irish law]] [[Creation date::+]] |format=count}}
|limit-prev={{{$limit|25}}}
|limit-next=25
|offset-prev={{{$offset|0}}}
}}</nowiki>
|trigger=afterpageload
|targetaction=replace
|class=d-block
|loadmoreid=cr-load-more
|updateurl=false
}}
}}

Result

Alternative solution

For the purpose of demonstration, we saw how the #cr-load-more parser function can be given right below the #ask query. To retrieve the total number of results, another #ask query with format=count is oassed to the total parameter.

There is another way though, which is to add #cr-load-more to an outro template of the main #ask query, or intro template if you prefer to stick it at the top. Let's say the template is called "Query loadmore 25".

{{#ask: ...
| ...
|outrotemplate=Query loadmore 25
}}

Now in "Template:Query loadmore 25", use the special variables available from SMW: #resultoffset, #querylimit and #rowcount :

{{#cr-load-more:
|id=cr-load-more
|total={{{#rowcount|}}}
|limit-prev={{{#querylimit|}}}
|limit-next=25
|offset-prev={{{#resultoffset|}}}
|class=btn btn-dark mt-3
|text=Load more results...
}}