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

Syntax sugar for no-query-result condition #28

Open
traut opened this issue Jan 10, 2024 · 9 comments
Open

Syntax sugar for no-query-result condition #28

traut opened this issue Jan 10, 2024 · 9 comments
Labels
draft enhancement New feature or request

Comments

@traut
Copy link
Member

traut commented Jan 10, 2024

Background

#142 introduces dynamic blocks. One typical pattern is to select which content to render based on the query result.

Design

Implement syntactic sugar t

content text {
  query = ".data.inline.my_elements"
  value = "The elements: {{ .data.inline.my_elements }}"

  when_empty_result content text {
    ...
  }
}

is unpacked into

dynamic content text {
  query = ".data.inline.my_elements"
  condition_query = "(.query_result == {} or .query_result == [] or .query_result == null) | not"

  value = "The elements: {{ .data.inline.my_elements }}"
}

dynamic content text {
  query = ".data.inline.my_elements"
  condition_query = ".query_result == {} or .query_result == [] or .query_result == null"

  value = "There are no elements"
}

Deliverables

  • the unit tests covering the new behavior
@traut traut added the enhancement New feature or request label Jan 10, 2024
@traut traut added this to the v0.1 milestone Jan 10, 2024
@dobarx
Copy link
Contributor

dobarx commented Feb 21, 2024

Shouldn't this be outside of the content block? Like using something like dynamic block with a condition when to render content.

@traut
Copy link
Member Author

traut commented Feb 21, 2024

It is pretty close to the dynamic block concept (I'm still working on the issue for that), indeed! We need to figure out an unobstructed syntax here -- it would be too cumbersome for the template authors to wrap every content block into another dynamic block. It needs to be a small addition, not a syntax change. Maybe these in-block fields can be syntactic sugar implemented through the dynamic blocks in the logic.

@traut traut modified the milestones: v0.1, v0.4 Feb 23, 2024
@traut
Copy link
Member Author

traut commented Apr 9, 2024

with #142 in mind, I think this issue still stands -- dynamic blocks are not well suitable for not-null checks

@dobarx
Copy link
Contributor

dobarx commented Apr 19, 2024

@traut What if we added a child block type for all content blocks? Something like:

content table {
  query = "..."
  ...
  empty_result {
    content text {
       value = "Empty data!"
    }
}

This would be a bit more flexible because we could specify any fallback content block.

@traut
Copy link
Member Author

traut commented Apr 19, 2024

that's neat, it's declarative and provides more options. To reduce the nest-iness, maybe it can be a content block with some flag, like

content table {
  query = "..."
  ...
  when_empty content text {
     value = "Empty data!"
  }
}

?

and we can use ref as well:

content table {
  query = "..."
  ...
  when_empty content ref {
     base = content.text.empty_data
  }
}

@traut
Copy link
Member Author

traut commented Apr 19, 2024

still not great :) it's confusing -- is empty_result / when_empty about the parent block or the nested block?

@dobarx
Copy link
Contributor

dobarx commented Apr 19, 2024

on_empty? Could also extend in the future with fallbacks for errors on_error.

@traut
Copy link
Member Author

traut commented Apr 19, 2024

oh, that's lovely.

content table {
  query = "..."
  ...
  on_empty content text {
     value = "Empty data!"
  }
}

content table {
  query = "..."
  ...
  on_empty content ref {
     base = content.text.empty_data
  }
}

would be ok, I think

@traut traut changed the title No query result condition for the content blocks Syntax sugar for no-query-result condition Apr 21, 2024
@traut traut added the draft label Apr 21, 2024
@traut
Copy link
Member Author

traut commented Apr 21, 2024

moving this to draft since #142 already can provide the functionality, even though in a bit wordy way

@traut traut removed this from the v0.4 milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants