Components¶
A component is an .rml file whose root is <component>: markup you write once and import into a
document with a <dc-import> element, with props for the values that differ and slots for the
children the importer supplies. The component file lives in a content root, by convention under
UI/Rml/ like a document. The Component sample imports one file, Card.rml, twice; the LocalState sample is below.
Define a component¶
<component>
<prop name="title" default="Card"/>
<prop name="accentColor" default="#3399ff"/>
<div class="cp-card">
<div class="cp-card-head" style:background-color="$accentColor">{{ $title }}</div>
<div class="cp-card-body"><slot/></div>
<div class="cp-card-foot"><slot name="footer"/></div>
</div>
</component>
<prop name="title" default="Card"/>declares a prop and its default. A prop with no default and no value is empty text.typeis optional:string(the default whentypeis missing),number,boolorfunction, as in<prop name="count" type="number" default="0"/>. A static value or default that does not fit fails the compile: anumbertakes a decimal number, abooltakestrue,falseor nothing. Afunctionprop names a view model function the component calls, as incall('model', $onPress). A{{ }}value is not checked. The type is used only while compiling and in the editor, where the prop row edits aboolwith a checkbox, anumberwith a number field and afunctionwith a function picker.- The body reads a prop as
$title: in an expression, as instyle:background-color="$accentColor", and inside{{ }}, as in{{ $title }}. <slot/>receives the children of the import.<slot name="footer"/>receives only the direct children that carryslot="footer".
Where a component's styles go
A component file holds markup only. Put its styles in the style sheet of the importing document (Component.rcss
here), or in an .rcss file with the component's name next to it (Card.rcss), which the compile links into every
document that imports the component.
The sample takes the first way:
.cp-card {
margin: 8px 0;
background-color: #303846;
border-radius: 4px;
}
.cp-card-head {
padding: 6px 12px;
border-radius: 4px;
color: #101418;
}
.cp-card-body {
padding: 8px 12px;
}
.cp-card-foot {
padding: 4px 12px 8px;
}
Import a component¶
<dc-import name="/ArcRmlUISamples/UI/Rml/Component/Card" title="Static title" accent-color="#ff9933">
<p>The default slot: any children.</p>
<p slot="footer">The footer slot.</p>
</dc-import>
<dc-import name="/ArcRmlUISamples/UI/Rml/Component/Card" title="{{ Title }}">
<p>Pressed {{ card.Count }} times.</p>
<button id="cp-press" slot="footer" class="cp-button" on:click="call('card', 'Increment')">Press</button>
</dc-import>
Props¶
nameis the absolute package path of the component file,.rmloptional, or an alias declared in the head (below). Any other name that does not start with/is a compile error, and no folder is searched.- A prop is an attribute of the import. A prop declared in camelCase is written in kebab-case:
accent-color="#ff9933"setsaccentColor. An attribute that names no prop is a compile error. - A prop value is static text (
title="Static title") or one whole-value expression (title="{{ Title }}"); text and{{ }}cannot be mixed in one value. A bound value reads the fields of the model the import sits in, hereTitleof the view model. - The import must be inside a
:model. The component's own reads and calls name their model in full, as the import's document does (the second import'sPressed {{ Count }} timesandPressbutton above). :for,:if,:modeland:keyon an import apply to the<div class="sc-host">, the wrapper element the plugin puts around each import, not to the component's content.
Alias in the head¶
A document can name a component once in its <head> and import it by that name. The Component sample declares Card:
<link rel="component" href="/ArcRmlUISamples/UI/Rml/Component/Card" as="Card"/>
<dc-import name="Card" title="{{ card.Title }}">
hrefis the full package path; a missing file is a compile error even when no import uses the alias.asis a letter followed by letters, digits,-and_. A missinghreforas, a duplicate alias, and a component link outside<head>are compile errors; an unused alias is silent.- The alias belongs to the document that declares it. It does not reach a component body: inside a component,
nameis a full path. - The links are removed from the compiled document.
Slots¶
Children of the import without a slot attribute go to the default slot, and a child with slot="footer" goes to the
slot of that name. A named slot with no children renders nothing. A slot name the component does not declare is a
compile error. In the sample, the second import puts a button in the footer, and the button's call('card', 'Increment')
runs on the document's view model:
UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "Samples")
FText Title = INVTEXT("Bound title");
UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "Samples")
int32 Count = 0;
UFUNCTION(BlueprintCallable, Category = "Samples")
void Increment();
Local state¶
A component keeps a value of its own with <state>, written beside its props. Its body reads it as state.<name> in any
binding (:if, class:*, {{ }}, :value) and writes it with a plain assignment in an event. The
LocalState sample's accordion opens and closes itself:
<component>
<prop name="title" default="Section"/>
<state name="open" type="bool" default="false"/>
<div class="lc-acc">
<button class="lc-button lc-acc-head" on:click="state.open = !state.open">{{ $title }} {{ state.open ? '-' : '+' }}</button>
<div class="lc-acc-body" :if="state.open"><slot/></div>
</div>
</component>
<state name="open" type="bool" default="false"/>must be self-closing and sit in the component header, before the body.nameis letters, digits and_, starting with a letter.typeisbool,numberorstring(the default);defaultis a literal of that type or one whole{{ expression }}reading props ({{ $start }}) and full model paths. A bad name, a duplicate, an unknown type or a default that does not fit fails the compile.- Every placed copy has its own value: the three accordions and the one per
:forrow open independently. - A state write is never sent to the game.
stateis reserved. A:foriterator or a<viewmodel>namedstateis a validator error, andstate.xthat no<state>declares fails the compile. Onlystateas the first name of a path is state:vendor.state.xis a field ofvendor.- Slot content means the state of the component whose file wrote it, not of the component it is placed in. In the sample's
Panel.rml, which declarespinned, the toggle sits in the slot of anAccordion, yet it changes the Panel's pin mark:
<component>
<prop name="title" default="Panel"/>
<state name="pinned" type="bool" default="false"/>
<div class="lc-box">
<div class="lc-box-head">{{ $title }}: {{ state.pinned ? 'pinned' : 'not pinned' }}</div>
<dc-import name="/ArcRmlUISamples/UI/Rml/LocalState/Accordion" title="Pin from the slot">
<p>The Panel is {{ state.pinned ? 'pinned' : 'not pinned' }}.</p>
<button class="lc-button" on:click="state.pinned = !state.pinned">Toggle pin</button>
</dc-import>
</div>
</component>
- A state returns to its default when its element is rebuilt: a
:ifthat turns false and true again, a keyed:forrow rebuilt out of order, a virtual list row that leaves the window. It is not kept across a document reload. - A view or screen (a document with
<head>) declares<state>in its<head>, next to<viewmodel>, with the same attributes; its{{ }}default reads only full model paths (a view has no props). Each placement of a view and each:forrow has its own value. A screen whose<body>has no:modelneeds nothing more: the state works without a model of your own.
Place a view¶
A view can be placed in another document with dc-import: a file with <rml> as its root and a
<head>, the kind of file you open as a screen. Its <body> children go inside the sc-host wrapper, and the same file still opens alone.
The EmbeddedViews sample places two views in one screen:
<dc-import name="/ArcRmlUISamples/UI/Rml/EmbeddedViews/PartyHeader"/>
<dc-import name="/ArcRmlUISamples/UI/Rml/EmbeddedViews/MemberCard" :for="m : party.Children" member="{{ m }}"/>
- A shared model. A
<viewmodel>of the view that is notmanualjoins the document's models. The same name with the same declaration (class, creation, path or resolver,OnClose, preview) is one shared model; the same name with a different declaration is a compile error. The header in the sample declarespartyas the screen does, so both read one object. - A given model. A
manualmodel of the view is given by an attribute of the import that is named like the model and holds one whole-value{{ path }}:member="{{ m }}". Each placed copy reads and calls its own object, so each row'scall('member', 'AddPoint')reaches only that row's member. Amanualmodel without such an attribute is a compile error. A given model does not join the document's models; inside the view,:modeland:forcannot use its name. - Attributes.
:for,:if,:keyand:virtualact on the wrapper as on a component, so the import needs a:modelaround it. A view has no props or slots: any other attribute, or any child of the import, is a compile error. - Head. The view's
<link type="text/rcss">and<style>join the document with no isolation; its<link rel="component">aliases work inside that view only. Its<meta>,<title>,<script>and other head tags are ignored, and so are the attributes of its<body>except:model. - A view can place components and other views; a view that places itself is a compile error.
When components expand¶
Imports, views included, are expanded when the document is compiled, into its .rmlc file, the compiled copy the plugin runs (Concepts). A
mistake in an import or a component, such as an unknown prop or slot name, is reported then
(Validation), not while the game runs.
Run it¶
Play in the map L_ArcRmlSamples and choose Component in the samples list (Samples); the console command is ArcRmlSamples.Open Component.

Next¶
- Documents: the head, opening and closing.
- View models: declaring and giving models.
- Expression reference: reading
state.<name>.