Control Flow ($if, $for)
PyWire provides special attributes for controlling the structure of your HTML.
Conditional Rendering ($if)
Section titled “Conditional Rendering ($if)”Use $if to conditionally include an element in the DOM.
---user = wire(None)---<div $if={user}> Welcome back, {user.name}!</div>Loops ($for)
Section titled “Loops ($for)”Use $for to render a list of items.
---items = wire(["Apple", "Banana", "Cherry"])---<ul> <li $for={item in items}> {item} </li> <li $if={len(items) == 0}> No items found. </li></ul>Visibility ($show)
Section titled “Visibility ($show)”Unlike $if, which adds or removes elements from the DOM, $show toggles the display: none CSS property. Use this for elements that need to toggle frequently without full DOM reconstruction.
---is_visible = wire(False)---<div $show={is_visible}> I'm hidden but still in the DOM!</div>