ListPages: Automatic Header

Posted by ErichSteinboeck on 25 Mar 2009 15:29, last edited by GoVegan on 09 May 2010 05:54

: automatic header heading listpages

rating: +7

When using module ListPages to select pages by specific criteria, there are two possible outcomes:

  • at least one page matches the criteria (resulting in a list of pages to be displayed), or
  • none of the pages match (resulting in nothing to be displayed)

You'd sometimes want the heading text for the list of pages to automatically adapt to the above situations, e. g. to show a heading text like

  • “Below you'll find a list of pages” if one or more pages are displayed, and
  • “No pages match” if ListPages does not display any pages

Here is a way, how you can do that.

Example

Click on a tag to list Community Blog pages tagged with any tag, listpages, howto, xyzzy

This is how the above example was coded:

[[module ListPages tag="@URL" category="blog" limit="10" separate="false"
appendLine="//No pages are tagged with the selected tag//[!----]"]]
//Below you'll find a list of pages tagged with the selected tag//
[!----]
# %%linked_title%%: %%tags%%
[!--
[[/module]]

How it Works

Because the "pages available" code is within the ListPages body, it will only display if there are any pages matching the ListPages criteria. Hidden comments are used to ignore the "pages available" message for every page after the first one — the ending [!-- code of the ListPages body is responsible for this. However, when the last page of the matching criteria is displayed, the ending [!-- code will instead hide the "pages unavailable" message.
Note: you must type the shown Wikidot comments ([!----]) and ([!--) exactly as-is. They are required to perform the desired function.

[[module ListPages selection-criteria separate="false"
appendLine="heading-text-to-be-shown-if-no-pages-are-displayed[!----]"]]
heading-text-to-be-shown-if-at-least-one-page-is-displayed
[!----]
listpages-body-that-usually-contains-%%…%%-variables
[!--
[[/module]]

Backlinks

Authors

ErichSteinboeck ErichSteinboeck . Please visit his/her userPage.

James Kanjo James Kanjo . Please visit his/her userPage.

Not so tricky - but clever!
Helmut_pdorf Helmut_pdorf 25 Mar 2009 17:21

This is very clear in the usage - and makes sence too!

Congratulations !


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 25 Mar 2009 17:21
You are the Master!
(account deleted) 25 Mar 2009 17:29

Erich,

Nice work! You are the Master Manipulator of the comment tag!

-Ed

by (account deleted), 25 Mar 2009 17:29
Thanks!
leiger leiger 25 Aug 2009 23:47

Will be using this! :)


~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server

by leiger leiger , 25 Aug 2009 23:47
ListPages Automatic Header
GoVegan GoVegan 23 Sep 2009 08:57

I refined the code to utilise a single ListPages module rather than two. As I was using the old code, I came across limitations due to trying to use a span element across different div blocks (which are automatically created as part of the ListPages module).

by GoVegan GoVegan , 23 Sep 2009 08:57
Re: ListPages Automatic Header
gerdami gerdami 23 Sep 2009 09:11

Thanks James, now please apply this solution to James Kanjo's activity

by gerdami gerdami , 23 Sep 2009 09:11
Brunhilda Brunhilda 23 Sep 2009 10:28

I especially like this because it is not limited to English, and anyone can write the text in his own language… Well done, guys!!!!

PS:I have already implemented it in Candidate For Delete page….


If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney

Last edited on 23 Sep 2009 10:32 by Brunhilda
by Brunhilda Brunhilda , 23 Sep 2009 10:28
singular/plural sensitivity
scottplan scottplan 02 Feb 2010 12:42

Erich's how-to addresses instances when a list is empty. I'm trying to think of how to distinguish between lists with 1 and more entries.

"1 comments" sounds too automated.

by scottplan scottplan , 02 Feb 2010 12:42
Re: singular/plural sensitivity
Timothy Foster Timothy Foster 02 Feb 2010 14:24

For the meantime, I've been using "1 comment(s)". Maybe this is possible with includes. Let me see…


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 02 Feb 2010 14:24
Re: singular/plural sensitivity
RobElliott RobElliott 02 Feb 2010 17:41

I tend to use "Number of comments: 1" as that works whatever the number is.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

by RobElliott RobElliott , 02 Feb 2010 17:41
Re: singular/plural sensitivity
Timothy Foster Timothy Foster 02 Feb 2010 22:13

I tried using some includes to do the job, and it worked well when not using ListPages. The problem was that defining %%comments%% as the value instead of 1 broke the idea. So for the moment, Rob's idea seems best, and it could be shortened to simply, "Comments: 1".


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 02 Feb 2010 22:13
NoriMori NoriMori 20 May 2015 20:40

Getting a weird issue when I try to use this in a template with a CountPages module for a header. I'm using:

[[module ListPages parent="." separate="false"
appendLine="[!----]"]]
+++ Subcategories
----
[[module CountPages parent="."]]
This category has the following %%total%% subcategories.
[[/module]]
[!----]
* %%title_linked%%
[!--
[[/module]]

All pages with no subcategories (i.e. child pages) should show nothing there. That works fine. But on the page I'm having trouble with (called "Characters"), which has one child page (called "Doctors"), I should be getting:

Subcategories


This category has the following 1 subcategories.

  • Doctors

Instead, I'm getting:

Subcategories


[some number]512223Characters

The number doesn't seem to have any relation to anything. It seems to change based on parameters I haven't figured out. Right now it's 98, but at one point it was something like 136. (And just now I changed "separate" from "false" to "no" and got 33626.)

However, if I open the editor and preview the page, I always get:

Subcategories


appendLine="[!----]"]]

  • Doctors

It's all terribly strange. I'm pretty sure it was working earlier, while I was still fooling around with the template. I'm not sure when it stopped working, so I don't know what change caused the problem.

by NoriMori NoriMori , 20 May 2015 20:40
Timothy Foster Timothy Foster 20 May 2015 21:14

It shouldn't work, as you cannot nest modules inside one another. Thankfully, you do not need CountPages at all since ListPages supports the %%total%% variable all on its own.


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 20 May 2015 21:14
NoriMori NoriMori 21 May 2015 06:11

Yes, but if I used the ListPages module by itself, it would give that message for every page listed.

…Eeeexcept no it wouldn't because the whole point of the comment tags is to stop it from doing that, isn't it? Oh my Lord I'm a moron. XD Forgive me, I'm very new at all this.

by NoriMori NoriMori , 21 May 2015 06:11
Timothy Foster Timothy Foster 21 May 2015 11:44

No problem; we're here to help when needed (:


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 21 May 2015 11:44

Related articles

Comments

Not so tricky - but clever!
Helmut_pdorf Helmut_pdorf 25 Mar 2009 17:21

This is very clear in the usage - and makes sence too!

Congratulations !


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 25 Mar 2009 17:21
You are the Master!
(account deleted) 25 Mar 2009 17:29

Erich,

Nice work! You are the Master Manipulator of the comment tag!

-Ed

by (account deleted), 25 Mar 2009 17:29
Thanks!
leiger leiger 25 Aug 2009 23:47

Will be using this! :)


~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server

by leiger leiger , 25 Aug 2009 23:47
ListPages Automatic Header
GoVegan GoVegan 23 Sep 2009 08:57

I refined the code to utilise a single ListPages module rather than two. As I was using the old code, I came across limitations due to trying to use a span element across different div blocks (which are automatically created as part of the ListPages module).

by GoVegan GoVegan , 23 Sep 2009 08:57
Re: ListPages Automatic Header
gerdami gerdami 23 Sep 2009 09:11

Thanks James, now please apply this solution to James Kanjo's activity

by gerdami gerdami , 23 Sep 2009 09:11
Brunhilda Brunhilda 23 Sep 2009 10:28

I especially like this because it is not limited to English, and anyone can write the text in his own language… Well done, guys!!!!

PS:I have already implemented it in Candidate For Delete page….


If slaughterhouses had glass walls, everyone would be vegan. - Paul McCartney

Last edited on 23 Sep 2009 10:32 by Brunhilda
by Brunhilda Brunhilda , 23 Sep 2009 10:28
singular/plural sensitivity
scottplan scottplan 02 Feb 2010 12:42

Erich's how-to addresses instances when a list is empty. I'm trying to think of how to distinguish between lists with 1 and more entries.

"1 comments" sounds too automated.

by scottplan scottplan , 02 Feb 2010 12:42
Re: singular/plural sensitivity
Timothy Foster Timothy Foster 02 Feb 2010 14:24

For the meantime, I've been using "1 comment(s)". Maybe this is possible with includes. Let me see…


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 02 Feb 2010 14:24
Re: singular/plural sensitivity
RobElliott RobElliott 02 Feb 2010 17:41

I tend to use "Number of comments: 1" as that works whatever the number is.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

by RobElliott RobElliott , 02 Feb 2010 17:41
Re: singular/plural sensitivity
Timothy Foster Timothy Foster 02 Feb 2010 22:13

I tried using some includes to do the job, and it worked well when not using ListPages. The problem was that defining %%comments%% as the value instead of 1 broke the idea. So for the moment, Rob's idea seems best, and it could be shortened to simply, "Comments: 1".


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 02 Feb 2010 22:13
NoriMori NoriMori 20 May 2015 20:40

Getting a weird issue when I try to use this in a template with a CountPages module for a header. I'm using:

[[module ListPages parent="." separate="false"
appendLine="[!----]"]]
+++ Subcategories
----
[[module CountPages parent="."]]
This category has the following %%total%% subcategories.
[[/module]]
[!----]
* %%title_linked%%
[!--
[[/module]]

All pages with no subcategories (i.e. child pages) should show nothing there. That works fine. But on the page I'm having trouble with (called "Characters"), which has one child page (called "Doctors"), I should be getting:

Subcategories


This category has the following 1 subcategories.

  • Doctors

Instead, I'm getting:

Subcategories


[some number]512223Characters

The number doesn't seem to have any relation to anything. It seems to change based on parameters I haven't figured out. Right now it's 98, but at one point it was something like 136. (And just now I changed "separate" from "false" to "no" and got 33626.)

However, if I open the editor and preview the page, I always get:

Subcategories


appendLine="[!----]"]]

  • Doctors

It's all terribly strange. I'm pretty sure it was working earlier, while I was still fooling around with the template. I'm not sure when it stopped working, so I don't know what change caused the problem.

by NoriMori NoriMori , 20 May 2015 20:40
Timothy Foster Timothy Foster 20 May 2015 21:14

It shouldn't work, as you cannot nest modules inside one another. Thankfully, you do not need CountPages at all since ListPages supports the %%total%% variable all on its own.


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 20 May 2015 21:14
NoriMori NoriMori 21 May 2015 06:11

Yes, but if I used the ListPages module by itself, it would give that message for every page listed.

…Eeeexcept no it wouldn't because the whole point of the comment tags is to stop it from doing that, isn't it? Oh my Lord I'm a moron. XD Forgive me, I'm very new at all this.

by NoriMori NoriMori , 21 May 2015 06:11
Timothy Foster Timothy Foster 21 May 2015 11:44

No problem; we're here to help when needed (:


Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me

by Timothy Foster Timothy Foster , 21 May 2015 11:44
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /