Skip to content
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

Boolean emptiness property for arrays #7

Closed
2 tasks
slavaschmidt opened this issue Oct 23, 2023 · 4 comments
Closed
2 tasks

Boolean emptiness property for arrays #7

slavaschmidt opened this issue Oct 23, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@slavaschmidt
Copy link
Contributor

Describe the feature

Please provide a way to conditionally render parts of the template where the condition is emptiness / non-emptiness of the list.

Use Case

When rendering lists as HTML, more often than not, it is needed to render parts of the layout only if there are some elements in the list, for example:

  • Table header and/or footer are only to be shown when there are rows in the table
  • Heading has to be visible only if there are paragraphs
  • Ordered and unordered lists might have an introduction and/or conclusion that only need to be shown if there are elements in the list

Proposed Solution

There are two possible ways to implement this functionality:

  • provide a synthetic property depending on the list emptiness, for example, when reading json. This gives full flexibility how the new key should be named
  • On the tokenizer level by extending the meaning of positive and negative sections for lists:
<+list>
<h1>Currenty on vacation</h1>
<ul>
<*list><li>{{.}}</li></list>
</ul>
</list>
<-list>Nobody is no vacation now</list>

The second way feels more elegant and will work for manually constructed data models as well.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

0.2.0

Environment details (OS name and version, etc.)

any

@slavaschmidt
Copy link
Contributor Author

Actually, the meaning of positive and negative sections could also be extended to maps, with the same meaning, checking for emptiness.

@hungrybluedev hungrybluedev self-assigned this Oct 28, 2023
@hungrybluedev hungrybluedev added the enhancement New feature or request label Oct 28, 2023
@hungrybluedev
Copy link
Owner

Implemented in 80e349f

@slavaschmidt Can you please add a sample usage in README and readme_test.v?

@slavaschmidt
Copy link
Contributor Author

The list is covered. I believe it might be better to wait for a possibility to iterate over maps to create a meaningful example involving map (non) emptiness.

@hungrybluedev
Copy link
Owner

Emptiness checking implemented for maps and lists so that they may act like Boolean sections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants