-
Notifications
You must be signed in to change notification settings - Fork 225
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
Expression support #117
Comments
I haven't planned to add expressions, expression support would encourage placing programming logic your templates. Stencils design goals are meant to express presentation and not programming logic. In your case, wouldn't that type of logic need to know if there is a next and previous page instead of blindly assuming you can + or - 1 to find a closest sibling page? If so, I think it would make more sense to create some kind of "paginator" which handles all the logic so that a template can just deal with presentation of pagination instead of the underlying logic behind pagination. For example: protocol Paginator {
var hasPrevious: Bool { get }
var hasNext: Bool { get }
var nextURL: String? { get }
var previousURL: String? { get }
var currentPageIndex: Int { get }
var totalPages: Int { get }
} {% if paginator.hasPrevious %}
<a href="{{ paginator.previousURL }}">Previous Posts</a>
{% endif %}
Current page {{ paginator.currentPageIndex }} out of {{ paginator.totalPages }}.
{% if paginator.hasNext %}
<a href="{{ paginator. nextURL }}">More Posts</a>
{% endif %} |
@kylef I was using I was mostly wondering if you've come across other use cases that might need expression support (or similar extra features)? |
@svanimpe For example, I needed even elements of the array to be displayed definitely, and odd elements in a different way, but the order of the output elements was the same as in the array. And using a class or structure to store the parity/odd of an element I don't think is rational. |
Are there any plans to support simple expressions like
{{ variable + 1 }}
?When rendering a template, I set a
page
variable and wanted to use expressions like this to generate links to the previous and next pages. I createdprevious
andnext
filters to work around this limitation.The text was updated successfully, but these errors were encountered: