1. Docs
  2. Guides

Who's using the app ($me)

Build a guestbook from the smallest app: notes in a table, a name and a color for whoever is holding the phone, every note signed by its writer, and then the whole guestbook shared.

8 steps · ends in a shared guestbook where every note is signed

<me> is the app's record of the person using it: one row per install of the app, with the fields you declare, such as a name or a favorite color. Only that install writes its row, and every row any install writes knows who wrote it. With sync on, everyone's notes come with their writer's name and color, without any sign-in.

This guide builds a guestbook. It starts on one phone and ends shared with everyone who has the app.

Step 1 of 8

Start with the smallest app

Every HAM document starts with <app>. A <screen> is one page of the app, and <main> holds what's on it: for now, one line of <text>.

app.ham · step 1
<app>    <screen>        <main>            <text>Hello</text>        </main>    </screen></app>
Step 1 on a phone: Start with the smallest app Step 1 on a phone, dark: Start with the smallest app
Step 1, drawn by the engine from the snippet beside it.

Step 2 of 8

Add a title bar and a color

<app-bar> puts the screen's title across the top, and <config primary_color="pink"> gives every control a pink. Use a named color like pink, teal or amber.

app.ham · step 22 new lines
<app>    <config primary_color="pink"/>    <screen>        <app-bar title="Guestbook"/>        <main>            <text>Hello</text>        </main>    </screen></app>
Step 2 on a phone: Add a title bar and a color Step 2 on a phone, dark: Add a title bar and a color
Step 2, drawn by the engine from the snippet beside it.

Step 3 of 8

Keep the notes

A <database> with one table, note, holding the text of each note. A <form> adds one: its field is named text, like the column, so the send button's #db.note.create takes it straight from the form. <@foreach> lists the notes, newest first.

app.ham · step 323 new lines
<app>    <config primary_color="pink"/>    <database name="guestbook"              version="1">        <model name="note">            <field name="text"                   required/>        </model>    </database>    <screen>        <app-bar title="Guestbook"/>        <main>            <column>                <form>                    <row>                        <input name="text"                               placeholder="Leave a note"                               flex="1"/>                        <button action="#db.note.create; $text = ''"                                icon="send"/>                    </row>                </form>                <@foreach in="note"                          order="created_at desc"                          as="n">                    <text>@{$n.text}</text>                </@foreach>            </column>        </main>    </screen></app>
Step 3 on a phone: Keep the notes Step 3 on a phone, dark: Keep the notes
Step 3, drawn by the engine from the snippet beside it.

Step 4 of 8

Ask who's signing

<me> declares the fields the app keeps about whoever uses this install. Here it's a name, read anywhere as $me.name and written with $me.name = ….

<@if test="!$me.exists"> shows a small "Who's signing?" form until this install has a name, and <@else> shows who you're signing as instead. Change runs #me.delete, which forgets the name, and the question comes back. @show="$me.exists" hides the note form until there's someone to sign it.

app.ham · step 418 new lines
<app>    <config primary_color="pink"/>    <database name="guestbook"              version="1">        <me>            <field name="name"/>        </me>        <model name="note">            <field name="text"                   required/>        </model>    </database>    <screen>        <app-bar title="Guestbook"/>        <main>            <column>                <@if test="!$me.exists">                    <column>                        <text>Who's signing?</text>                        <input name="who"                               label="Your name"/>                        <button @click="$me.name = $who">That's me</button>                    </column>                <@else>                    <row>                        <text>Signing as @{$me.name}</text>                        <button @click="#me.delete"                                variant="text">Change</button>                    </row>                </@if>                <form @show="$me.exists">                    <row>                        <input name="text"                               placeholder="Leave a note"                               flex="1"/>                        <button action="#db.note.create; $text = ''"                                icon="send"/>                    </row>                </form>                <@foreach in="note"                          order="created_at desc"                          as="n">                    <text>@{$n.text}</text>                </@foreach>            </column>        </main>    </screen></app>
Step 4 on a phone: Ask who's signing Step 4 on a phone, dark: Ask who's signing
Step 4, drawn by the engine from the snippet beside it.

Step 5 of 8

Sign every note

Every row records the install that wrote it, and $n.owner is that install's <me> row. So @{$n.owner.name} is the writer's name, read when the note is shown: change your name, and your old notes follow. $n.mine is true for the notes this install wrote, and marks them "(you)".

app.ham · step 56 new lines
<app>    <config primary_color="pink"/>    <database name="guestbook"              version="1">        <me>            <field name="name"/>        </me>        <model name="note">            <field name="text"                   required/>        </model>    </database>    <screen>        <app-bar title="Guestbook"/>        <main>            <column>                <@if test="!$me.exists">                    <column>                        <text>Who's signing?</text>                        <input name="who"                               label="Your name"/>                        <button @click="$me.name = $who">That's me</button>                    </column>                <@else>                    <row>                        <text>Signing as @{$me.name}</text>                        <button @click="#me.delete"                                variant="text">Change</button>                    </row>                </@if>                <form @show="$me.exists">                    <row>                        <input name="text"                               placeholder="Leave a note"                               flex="1"/>                        <button action="#db.note.create; $text = ''"                                icon="send"/>                    </row>                </form>                <@foreach in="note"                          order="created_at desc"                          as="n">                    <column>                        <text>                            @{$n.owner.name}@{$n.mine ? ' (you)' : ''}                        </text>                        <text>@{$n.text}</text>                    </column>                </@foreach>            </column>        </main>    </screen></app>
Step 5 on a phone: Sign every note Step 5 on a phone, dark: Sign every note
Step 5, drawn by the engine from the snippet beside it.

Step 6 of 8

Pick a color

<me> gets a second field, color. Three <chip variant="choice">s pick one into $pick, and That's me saves it with the name. An <avatar> beside each note takes its color from the writer, $n.owner.color, and your own avatar shows next to your name.

app.ham · step 631 new lines
<app>    <config primary_color="pink"/>    <database name="guestbook"              version="1">        <me>            <field name="name"/>            <field name="color"/>        </me>        <model name="note">            <field name="text"                   required/>        </model>    </database>    <screen>        <app-bar title="Guestbook"/>        <main>            <column>                <@if test="!$me.exists">                    <column var-pick="pink">                        <text>Who's signing?</text>                        <input name="who"                               label="Your name"/>                        <row>                            <chip variant="choice"                                  label="Pink"                                  selected="$pick == 'pink'"                                  @click="$pick = 'pink'"/>                            <chip variant="choice"                                  label="Teal"                                  selected="$pick == 'teal'"                                  @click="$pick = 'teal'"/>                            <chip variant="choice"                                  label="Amber"                                  selected="$pick == 'amber'"                                  @click="$pick = 'amber'"/>                        </row>                        <button @click="$me.name = $who; $me.color = $pick">That's me</button>                    </column>                <@else>                    <row>                        <avatar icon="person"                                color="$me.color"                                size="44"/>                        <text>Signing as @{$me.name}</text>                        <button @click="#me.delete"                                variant="text">Change</button>                    </row>                </@if>                <form @show="$me.exists">                    <row>                        <input name="text"                               placeholder="Leave a note"                               flex="1"/>                        <button action="#db.note.create; $text = ''"                                icon="send"/>                    </row>                </form>                <@foreach in="note"                          order="created_at desc"                          as="n">                    <row>                        <avatar icon="person"                                color="$n.owner.color"                                size="36"/>                        <column flex="1">                            <text>                                @{$n.owner.name}@{$n.mine ? ' (you)' : ''}                            </text>                            <text>@{$n.text}</text>                        </column>                    </row>                </@foreach>            </column>        </main>    </screen></app>
Step 6 on a phone: Pick a color Step 6 on a phone, dark: Pick a color
Step 6, drawn by the engine from the snippet beside it.

Step 7 of 8

Share it with everyone

sync="on" on the database shares it between every install of the app. Each install keeps its own <me> row and writes only that one, and the guestbook now shows everyone's notes, each signed with its writer's name and color. A copy opened inside the Hype Apps player keeps its own guestbook, so share an installed app to see it fill up.

app.ham · step 73 new lines
<app>    <config primary_color="pink"/>    <database name="guestbook"              version="1"              sync="on">        <me>            <field name="name"/>            <field name="color"/>        </me>        <model name="note">            <field name="text"                   required/>        </model>    </database>    <screen>        <app-bar title="Guestbook"/>        <main>            <column>                <@if test="!$me.exists">                    <column var-pick="pink">                        <text>Who's signing?</text>                        <input name="who"                               label="Your name"/>                        <row>                            <chip variant="choice"                                  label="Pink"                                  selected="$pick == 'pink'"                                  @click="$pick = 'pink'"/>                            <chip variant="choice"                                  label="Teal"                                  selected="$pick == 'teal'"                                  @click="$pick = 'teal'"/>                            <chip variant="choice"                                  label="Amber"                                  selected="$pick == 'amber'"                                  @click="$pick = 'amber'"/>                        </row>                        <button @click="$me.name = $who; $me.color = $pick">That's me</button>                    </column>                <@else>                    <row>                        <avatar icon="person"                                color="$me.color"                                size="44"/>                        <text>Signing as @{$me.name}</text>                        <button @click="#me.delete"                                variant="text">Change</button>                    </row>                </@if>                <form @show="$me.exists">                    <row>                        <input name="text"                               placeholder="Leave a note"                               flex="1"/>                        <button action="#db.note.create; $text = ''"                                icon="send"/>                    </row>                </form>                <@foreach in="note"                          order="created_at desc"                          as="n">                    <row>                        <avatar icon="person"                                color="$n.owner.color"                                size="36"/>                        <column flex="1">                            <text>                                @{$n.owner.name}@{$n.mine ? ' (you)' : ''}                            </text>                            <text>@{$n.text}</text>                        </column>                    </row>                </@foreach>            </column>        </main>    </screen></app>
Step 7 on a phone: Share it with everyone Step 7 on a phone, dark: Share it with everyone
Step 7, drawn by the engine from the snippet beside it.

Step 8 of 8

Style it

The finishing touches: the question becomes a <card>, That's me a full-width pill, each note a soft pink bubble beside its writer's avatar, and an empty guestbook invites the first signature.

That's a guestbook where every note knows its writer, and nobody had to make an account.

app.ham · step 825 new lines
<app>    <config primary_color="pink"/>    <database name="guestbook"              version="1"              sync="on">        <me>            <field name="name"/>            <field name="color"/>        </me>        <model name="note">            <field name="text"                   required/>        </model>    </database>    <screen>        <app-bar title="Guestbook"/>        <main>            <column style="w-full p-16 gap-14">                <@if test="!$me.exists">                    <card style="w-full p-20 gap-12"                          var-pick="pink">                        <text style="font-xl font-bold">Who's signing?</text>                        <input name="who"                               label="Your name"/>                        <row style="gap-8">                            <chip variant="choice"                                  label="Pink"                                  selected="$pick == 'pink'"                                  @click="$pick = 'pink'"/>                            <chip variant="choice"                                  label="Teal"                                  selected="$pick == 'teal'"                                  @click="$pick = 'teal'"/>                            <chip variant="choice"                                  label="Amber"                                  selected="$pick == 'amber'"                                  @click="$pick = 'amber'"/>                        </row>                        <button @click="$me.name = $who; $me.color = $pick"                                variant="filled"                                style="w-full rounded-full">That's me</button>                    </card>                <@else>                    <row style="w-full gap-12 items-center">                        <avatar icon="person"                                color="$me.color"                                size="44"/>                        <text style="font-bold"                              flex="1">Signing as @{$me.name}</text>                        <button @click="#me.delete"                                variant="text">Change</button>                    </row>                </@if>                <form @show="$me.exists">                    <row style="w-full gap-8 items-center">                        <input name="text"                               placeholder="Leave a note"                               flex="1"/>                        <button action="#db.note.create; $text = ''; haptic:light"                                variant="filled"                                icon="send"                                style="rounded-full"/>                    </row>                </form>                <@foreach in="note"                          order="created_at desc"                          as="n">                    <row style="w-full gap-10 items-start">                        <avatar icon="person"                                color="$n.owner.color"                                size="36"/>                        <column flex="1"                                style="p-12 gap-2 rounded-2xl bg-pink-50 dark:bg-pink-950">                            <text style="font-sm font-bold">                                @{$n.owner.name}@{$n.mine ? ' (you)' : ''}                            </text>                            <text>@{$n.text}</text>                        </column>                    </row>                <@empty>                    <text style="muted text-center py-24">No notes yet. Be the first to sign.</text>                </@foreach>            </column>        </main>    </screen></app>
Step 8 on a phone: Style it Step 8 on a phone, dark: Style it
Step 8, after Maya signs, drawn by the engine from the snippet beside it.

This page is also Markdown, and all of HAM is in llms.txt.