CountBetweenMarkers-Talk

Summary: Talk page for CountBetweenMarkers.
Maintainer: Holger Kremb
Users: (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

Expansion?

Could you (or someone else) extend the recipe? I could use a way to count specific short strings on a page, or even better, between markers.Ideally, I envision:

On a page, PTVs are created for strings whose count I'd like to know:

(:Countstring01: foo:)
(:Countstring02: bar:) etc.

The recipe then outputs the numbers as {$cs01}, {$cs03}, etc.

I haven't found any other approach besides CountGlyphs: https://www.pmwiki.org/wiki/Cookbook/CountGlyphs.

Sorry for asking for help instead of programming myself, but I don't have the necessary skills!

26.01.2026 – 20:43 nitram


Hi, Nitram,
Thanks for the suggestion — this is an interesting use case.

For now, CountBetweenMarkers is intentionally limited to counting raw text lines between two markers, to keep the recipe simple and focused.

Counting arbitrary strings (optionally scoped between markers) would probably be better implemented as a separate recipe or as an optional extension, as it introduces additional complexity and different semantics.

You are right that CountGlyphs is currently the closest existing solution, although it works globally on the page and not within marker ranges.

I’ll keep this idea in mind — if such an extension is added in the future, it will likely be documented separately to avoid overloading the original recipe.
26.01.2026 - 21:56 Holger


I’ve put together a small helper script and uploaded it here: https://kremb.net/uploads/Scripts/pmcountstr.zip (deleted in the meantime)

Feel free to test it and let me know if it behaves as expected or if you notice any issues. If it proves useful and stable, I’m planning to submit it as an official PmWiki Cookbook recipe.

Feedback is very welcome.
26.01.2026 - 22:36 Holger

Thank you so much! It works perfectly right away and is easily customizable. However, I can't get the page variable to work; I've tried everything. Any ideas? Thanks, and good night for now (from Siegen/Germany).
It would be nice to have an option for "whole word". 27.01.2026 – 00:16 nitram

Thanks for the feedback, glad it’s useful 🙂 About the PageVariable: this is AFAIK a PmWiki rendering-order thing, not a bug. The variable set via id= is only available *after* the markup has been processed. So it won’t work inline or before the (:pmcountstr:) directive.

Hopefully that will work: (:pmcountstr needle=foo id=c01:)

... later on the page ...

{$c01}

But this won’t: {$c01}

(:pmcountstr needle=foo id=c01:)

If you need the value inline, just use the directive output directly without id=. This is the same behavior as with pagelist counters and other PageVariables.
Greetings from northern Germany and good night <g>. 27.01.2016 00:24 Holger

The PageVariable remains empty for me, even though it's at the very end. I would have liked to use it to perform further calculations (evaluating a simple school timetable). But thank you, it's useful even without it. 27.01.2026 – 09:56 nitram

Hi nitram,

I’ve published the new cookbook CountOccurrences and set up a public test page so you can see all variants in a real-world setup.

Cookbook:

https://www.pmwiki.org/wiki/Cookbook/CountOccurrences

Test page: https://kremb.net/Tests/Temp

The test page is in German, but the examples and expected results should be easy to follow. Please note: the test page is temporary and will be removed again later in February.

Thanks again for the idea — it directly led to this recipe. Challenges are there to be taken on 😉

27.01.2026 - 16:11 Holger


Talk page for the CountBetweenMarkers recipe (users).