-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IDEA] List widget allows for optional header and/or footer, shown only if list is non-empty #5302
Comments
Related #2202 - Add preMessage parameter to listwidget |
Thx Mat. I knew there has been a discussion somewhere. ... You saved me from writing my concerns again. I think the problem is, that the OP is a relatively specialized usecase, which from my point of view, isn't "best practice". I'm no fan of "hidden information". So if there is a possibility of "Subtasks" the user should be aware, that there are no subtasks. ... Hiding the "header" shouldn't be an option here. ... But that's only my point of view. |
Thanks @rmunn, that's very clear. To answer your question, I think one would indeed need both However, there are some downsides with this approach. The first is that it doesn't work well for the usecase you mention of an optional heading before a list. The trouble is that we would normally wrap the The other downside is that it makes the list widget even more complex. It was added quite early in TW5's development to get the story river up and running. There is a lot of "magic" in the implementation (e.g. having separate edit and view templates) that we would handle differently now that we have so much more flexibility. One interesting proposal we had in the past was to add counter variables to the list widget -- see #1330 (comment) and the later discussion at #3384, which would provide an alternate means to support the OP. I made a later proposal in #1523, but I think now I would advocate a new widget |
+1 I would rather introduce a new widget than add more complexity to the |
I agree about a new widget, and the coder in me wants to call it foreach instead of for, but I don't know if that would be clearer for most people. |
Solving the OT and related issues would stand to propel tiddlywiki to wards a 4th Generation report language. I believe there is now a way to obtain an index value, However it is not so efficient; You must test the original filter every time.
Finding a list item of 1 would allow the list widget contents (or template) to trigger a heading. The only way to detect the footer would be first to count the number of items and test for the last. Perhaps a simple solution would be for the list widget to have a built in count, ie given the filter result Not withstanding the above given the list widgets overloading perhaps if a new widget was to be written for more general purposes perhaps it could be a reportWidget including a total item count, header and footer triggers and an item count incremented for each item listed. An The idea of a reportWidget is in keeping with tiddlywikis excellent list handling facilities and could include multiple field based accumulators, like the new Reduce Operator. We could even introduce break points eg on change in fieldname value "display this" eg on newState. I would be happy to prepare design requirements if someone can help build it. Tones |
Post script, Other page handling features would also be appropriate inside a reportWidget that may not be valid in the listWidget. Eg; variable that exist only within the report widget, that can be reset according to conditions in the report widget. Tones |
I think that is what is discussed over at #3384. |
@rmunn has the requirement been met by the introduction of the counter and other new variables in the listWidget? |
It's almost met, but not quite. I want to be able to produce something like the following: <b>Header</b>
<ul>
<li>One</li>
<li>Two</li>
</ul>
<b>Footer</b> Which renders as: Header
But if the list is empty, I want "Header" and "Footer" to be completely absent. I don't think I can produce this HTML with the list widget's new counter-first and counter-last variables. I'd like to do something like this: <$list filter="One Two" variable="item">
<$if filter="[<counter-first>match[true]]">
<b>Header</b>
<ul>
</$if>
<li><<item>></li>
<$if filter="[<counter-last>match[true]]">
</ul>
<b>Footer</b>
</$if>
</$list> But 1) there's no |
There is an if, it's named
|
The only problem is the performance hit. |
@Jermolene ... Would the just an idea |
Hi @rmunn @saqimtiaz the subtlety is that these header and footer entries need to be outside the
No, for the same reason: the values of variables can only be changed by re-rendering their child widgets, which wouldn't happen if we were moving nodes around. |
I think these can be simply addressed by a macro similar to list-links. There are cases like list-search (see Shiraz) where it creates a list of items from given tiddler plus a search box at the top! So, it seems simple macros with current $list widget can cover these use cases! Just my 2 cents! |
This should become possible to implement myself once #6666 is implemented: I'll be able to write a
Edit: And with the
This makes the header stay outside of the So once #6666 is merged, I'll close this issue as I'll be able to implement this feature myself without needing to change core TW. |
I would not say that the there is no value in header and footer features however I have already made a working solution by using the counter variable. But first I use the filter to be used for the list and set a total
above code not actually run. |
Now that #6666 has been merged and released, it's time to close this feature request as it's possible to do this myself now. Plus, I'm currently working on PR #7691 that adds an
That's perfectly adequate to satisfy me, and looks nice and clean and readable too. Closing this feature request as now TW can do what I wanted. |
@rmunn https://liststyles.tiddlyhost.com/#:listheader%20About I didn't announce it publicly because.... well, I don't expect anyone will use it anyway. |
I am yet to publish it but I have resolved this with a custom widget. Happy to share. |
Is your feature request related to a problem? Please describe.
I often want to show lists preceded by some kind of header, but only show the header if the list is non-empty. E.g., in a tiddler that represents one task on a todo list, I might want it to look like this:
The list of subtasks is presented by a
$list
widget, drawing from thesubtasks
field of the task tiddler. If thesubtasks
field is missing or empty, then I'd like to not show the Subtasks header at all. It would be nice if I could do this entirely within the$list
widget, so that the "Subtasks" section of my todo template could be kept simple.Describe the solution you'd like
The
$list
widget would acquire two new attributes, possibly namedheader
andfooter
(though I've also consideredprefix
andsuffix
as possible names). Their contents would be wikitext that would be rendered before and after the list, respectively. If the list's filter resolves to empty output (so that theemptyMessage
attribute is rendered instead) then the header and footer are not rendered. (If the user wants the header to always be rendered whether or not the list is empty, it's trivial to move that text to just before the list widget, or to include it as part of theemptyMessage
).It might also be a good idea to have attributes called
headerTemplate
andfooterTemplate
, to parallel thetemplate
andeditTemplate
attributes that already exist. Those templates would be rendered with the currentTiddler value being unchanged (i.e., it's probably the tiddler that contains the$list
widget), just as if they were a normal transclusion. I haven't decided yet if bothheaderTemplate
andheader
should be allowed as attributes, or if just one would be better. If both were allowed, we would need to decide which one "wins" if both are present and non-empty; I'd be inclined to say thatheaderTemplate
wins overheader
, to parallel how other widgets tend to work (e.g., how the$set
widget has thetiddler
attribute trump thevalue
attribute if both are set).Describe alternatives you've considered
The way to achieve this right now would be to use a combination of widgets, such as:
But I'd rather write that as:
The text was updated successfully, but these errors were encountered: