smalljs$molSearch⌘ KDocsPlaygroundCompareEcosystemAboutEN
ViewsGetting StartedIntroductionMental modelGetting StartedFrom TypeScript to view.treeProject StructureToolingEssentialsInstallationViewsState & ReactivityRoutingRenderingTestingDeploymentTroubleshootingDataData FetchingData SchemasGiper BazaMoreShowcaseFrom React, Vue & SvelteCookbookAdvancedPluginsModule metadataOfflineGhost viewsAboutFAQTeamReleasesAPI$mol_button_major$mol_button_minor$mol_string$mol_number$mol_text$mol_paragraph$mol_list$mol_row$mol_link$mol_check$mol_switch$mol_select$mol_scroll$mol_page$mol_pick

Views

A view is a component: a node in the UI tree with its own layout, behaviour, and styles. This chapter covers how views are declared, wired to logic, composed, and reused.Coming to view.tree cold: From TypeScript to view.tree builds one component twice, once as a hand-written class and once as a tree, and shows the code the tree compiles to. Read it first if the syntax below feels like a new language rather than shorthand.

Three files, one component

A component $my_card lives in my/card/ and is described by up to three files, each with a clear job:card.view.treewhat the component is: its structure and default bindings.card.view.tshow it behaves: TypeScript methods, reactive state.card.view.css.ts — how it looks: typed styles checked by the compiler.Keeping structure, behaviour, and style apart is deliberate — each file stays small and readable, and the layout is never tangled with logic.None of the three is mandatory on its own. Drop card.view.tree and write the class directly in namespace $: the structure becomes ordinary methods and the component still works. The rest of this chapter uses the tree, because that is what the structure looks like once the plumbing is generated for you.

The view.tree language

view.tree describes structure declaratively. Indentation is nesting; there are no closing tags.1$my_card $mol_view2 sub /3 <= Title $mol_view4 sub / <= title \5 <= Body $mol_view6 sub / <= text \Every capitalized name (Title, Body) becomes a real property you can reach, override, or style. Every lowercase binding (title, text) becomes a value you can compute in .view.ts.

Binding properties

Two operators connect a property to its source:<= one-way: the child reads a value from the owner.<=> two-way: the value flows both directions — used for inputs.1$my_form $mol_view2 sub /3 <= Field $mol_string4 value? <=> text? \Here the input's value and the owner's text stay in sync automatically: type in the field and text updates; set text in code and the field reflects it.

Wiring to behaviour

A binding with no default is implemented in .view.ts. The class extends the generated base of the same name:1namespace $.$$ {2 export class $my_card extends $.$my_card {3 @ $mol_mem4 title() {5 return 'Untitled'6 }7 }8}
Edit this page on GitHubWas this helpful?YesNoPreviousInstallationNextState & Reactivity
On this pageThree files, one componentThe view.tree languageBinding propertiesWiring to behaviourAttributes and element typeLists and keyed viewsConditional viewsComposition and reuseNext
Type to search the documentation.