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

Theoretical implementation of an IF statement #3

Closed
Eventpicker opened this issue Dec 20, 2022 · 2 comments
Closed

Theoretical implementation of an IF statement #3

Eventpicker opened this issue Dec 20, 2022 · 2 comments

Comments

@Eventpicker
Copy link
Contributor

Hello ken107
I am trying to implement an IF statement in your customization directories. I have tried to refactor your code and now i understand the individual steps as you proceeded. However, I have not yet managed to implement a good IF statement.

My goal is to program something like this:

JS:
window.expr = true;

HTML:
<div bind-statement-if="#expr"><p>SUCCESS</p><div>

When "expr" true then:
<div><p>SUCCESS</p><div>

When "expr" false then:
<div><div>

I am trying to implement a statement that removes the 'innerHTML' when the expression is false and adds it when it is true.
could you please help me here and send me a theoretical instruction on how to implement this?

Would be amazing!

This implementation could be also a extension for the docs when you want it.

@ken107
Copy link
Owner

ken107 commented Dec 20, 2022

Hi Thomas,

I usually do quick-and-dirty if statements like this: <p bind-repeater-if="#expr ? 1 : 0">SUCCESS</p>. Basically using a 0/1 repeater. And I put it on the element that will be toggled on/off.

Generally you can declare custom directives through rewriting attributes, like in this example:
examples/todolist3/mycustomdirectives.js

@Eventpicker
Copy link
Contributor Author

uhh thats smart!
Thank you for the quick response!

Regards
Thomas

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

No branches or pull requests

2 participants