Adding previous/next buttons (for blog-entry batches)

  • “in the same filter.” limits possibilities, but not inside TiddlyWiki script.

Actually there are a few ways to do this. You can use the $set widget to set a list-variable (A variable containing a list) and access the list members by an index, or use allbefore<currentTiddler>count[]to find the position in a list.

  • But this discussion may go too far off topic.

Other methods include;

  • storing a list in a javascript array
  • Maybe using the map accumulator add 1 not multiple?
  • Inside a list widget with the counter variable

I’ve probably just duplicated code that you’ve already received, but it felt like a fun coding exercise that I wanted to jump into without looking at other code already given.

Drag the attached into TiddlyWiki.com

List of tiddler titles in groups of 10 per page.json (1.3 KB)

The result:

2 Likes

That’s going to be difficult with a list like a b c d c a b e f a b c. Should b yield 2, 7, 11, or all of them?

I think I’d expect it to follow the normal deduplication rules. a b c d c a b e f a b c = d e f a b c unless you’re taking special steps to preserve the duplicates, so b = 5. If you are preserving duplicates, then b = 2 7 11.

(Edit: This would be the converse of the nth operator: a b c d c a b e f a b c +[nth[5]] = b, while ... +[nth[2]] = e, and +[nth[7]] and +[nth[11]] return a blank result. =a =b =c d =c =a =b e f =a =b =c +[nth[11]] does return b.)

It’s an interesting point, though, and I admit I haven’t checked to see how Evan chose to handle it.

EDIT now that I’m back at my computer: Evan’s addposition operator does work exactly as I’d expect.

image

1 Like

Nice! One issue. This is overcomplicated, occasionally wrong, and mostly unnecessary:

<$let tid_count={{{ [all[tiddlers]sort[]limit[54]count[]] }}}
      page_count={{{ [<tid_count>divide[10]floor[]] =[<tid_count>divide[10]subtract<page_count>!match[0]then[1]] +[sum[]] }}}>

If you change the limit to 60, you will get a page_count of 7.

I don’t know if his is because of rounding in the Javascript’s underlying floating point specification, or has something to do with the odd use of <page_count> in the definition of page_count, but I’m not sure that’s important, because it can be much simplified with the use of ceil instead of floor:

<$let tid_count={{{ [all[tiddlers]sort[]limit[60]count[]] }}}
      page_count={{{ [<tid_count>divide[10]ceil[]] }}}> 

Hi @Springer,
inspired by the code I’d need a little help to improve the code:

<$let topic="2023" blogcount={{{ [tag<topic>!sort[published]count[]] }}} interval=23>

Suche nach __<<topic>>__  <span style="font-size: 0.7em; color: rgba(204, 204, 255, 0.6);">&emsp; <$text text={{{ [{$:/blog-startval}] }}}/> - <$text text={{{ [{$:/blog-startval}add<interval>subtract[1]] }}}/> (von <<blogcount>>)</span>

grafik

<blogcount> is the max: 245
adding the <interval> will exceed the <blogcount> (=253)

I’d like to have:

"If <$text text={{{ [{$:/blog-startval}add<interval>subtract[1]] }}}/> is gteq <blogcount> than <blogcount>; else <$text text={{{ [{$:/blog-startval}add<interval>subtract[1]] }}}/>

means: If 253 >= 245 than 245; else add the interval 23

How can that be done?

Thanks, Stefan

If I understard correctly, what you’re concerned about (adding the interval only if it wouldn’t send the value past the actual count of items) is what I tried to handle by having the “NEXT” button show up only if adding the interval would not result in a value beyond the blogcount:

<$list filter="[<thisTiddler>get[startval]add<interval>compare:number:lt<blogcount>]">
@@float:right;<$button><$action-setfield $tiddler=<<thisTiddler>> $field=startval startval={{{ [<thisTiddler>get[startval]add<interval>] }}} />
NEXT (Show posts from <$text text={{{ [<thisTiddler>get[startval]add<interval>add[1]] }}}/> to <$text text={{{ [<thisTiddler>get[startval]add<interval>add<interval>] }}}/>)
</$button>@@</$list>

Of course, you could change what action the button does, instead. But I think having the button disappear (or more elegantly, make itself greyed-out) makes for a clearer user interface.

If I’ve misunderstood, please follow up!

Try adding the min[...] filter, like this:

{{{ [{$:/blog-startval}add<interval>subtract[1]min<blogcount>] }}}

The result will be the smaller of either the calculated value or the <blogcount> value.

1 Like

I did the same thing (greying out the button using the disabled attribute) in my version, but the defensive coder in me thinks that this is not enough. I haven’t looked at your implementation closely, but if its anything like mine, it paginates based on data that users could easily alter (two fields in the the wrapping tiddler.) This was just a throw-away for me, but for serious usage, that should probably be addressed.

Meh, “much simplified” is of no value to me, at the first stage of just identifying the general process and the fundamental parts. At that stage, like in any other, it is about what gets to the current milestone the quickest.

Like I could not remember “ceil”, and it was just quicker for me to plop in there what I remembered rather than go looking for “ceil”. No time for that distraction.

And then, when the proof of concept is valid, code refactoring/cleanup before going to the next step of an incremental and iterative process.

Such is my process.

I probably wouldn’t have bothered replying if it weren’t getting the wrong answer for 60. I work the same way. But broken code should be noted and eventually addressed.

Bug fixed and field added to quickly adjust the limit of tiddlers processed.

List of tiddler titles in groups of 10 per page.json (1.5 KB)

Looks great!

It’s always interesting to see the variety of approaches offered.

That’s just proof of concept prototype.

I’d refactor it to pretty it up, condense it, and ready it for general-purpose use (each item listed in a page would be a details element (so see the whole picture and pop open the bits of interest, which I much prefer), but I’ve completely lost interest in the target.

Once I see the foundational bits work, and I know what the final solution would look like (i.e. there is no longer a “how would I do that?” challenge), I become entirely disinterested and move along to the next “I wonder how I’d do that” shiny object.

Understood. Mine as well, and I imagine @springer’s also.

I’m the same way. The question is whether I can sustain the curiosity long enough to complete something I really want to accomplish. :frowning_face:

1 Like

Perfect - thanks Eric, thats exact what I asked for. :+1:

@Springer, @Charlie_Veniot, @Scott_Sauyet thanks for your feedback / input.

Greetings, Stefan