Skip to content

Attribute cheat sheet ​

Rust functions that produce attributes ​

PHP's Blade directives are functions you call in handlers in Rust. They return Attributes (or a string), which you pass to templates with with_html or add to components with .attributes(..).

PHPRustEffect
@renderObject('name', [...])runtime::render_object("name", &[Allow::…])Permission boundary + namespace
@renderBlade(Controller::class, 'components', [...], '#target')runtime::render_trigger("name", RenderMethod::Components, Some("#target"), &[...])Renders on click
@renderAuto(Controller::class, 'components', [...])runtime::render_auto("name", RenderMethod::Components, &[...])Renders after load (the element needs an id)
@renderInline(Controller::class, [...])Call your fragment function directly and put the Html in the templateRendered in place by the server
@linker('alias')linker::mount::<C, User>(&user, args).await?.html()Linker mount point
@linkerBind([...])linker::bind(&json!([...]))Several Linker triggers on one element
@linkerRefSeed('ref', $seed)Output <script type="application/json" data-linker-ref-seed="ref"> yourself (example)Initial data for dom.repeat
SiteEndpoints::headTags(){{ cg_head() }} (needs the share_head middleware)CSRF, render token, endpoint meta
<html {!! … !!}><html{{ cg_html_attrs() }}>The endpoint meta name

Client state data-state-* ​

AttributePermissionExample
data-state-initwrite"open=false tab=list"
data-state-bindwrite"keyword"
data-state-setwrite"tab=chart" (Button::state_set)
data-state-togglewrite"open" (Button::state_toggle)
data-state-textread"matchCount" / "@cartCount"
data-state-showread"open" / "!open"
data-state-classread"open:is-open"
data-state-isread"step=2"
data-state-is-classread"step=2:is-current; step>2:is-done"

The permissions correspond to Allow::StateRead (read) and Allow::StateWrite (write). A leading @ means a global key.

Render fragments data-render-* ​

AttributeEffect
data-render-blade-object / data-render-allowA render object (produced by render_object)
data-cg-event="renderBlade"Trigger (produced by render_trigger)
data-render-autoRenders automatically after load (produced by render_auto)
data-render-nameThe name from render::register
data-render-methodcomponents / isolated / toast / page
data-render-targetSelector for where to insert
data-param-*The params sent (names in kebab-case, runtime::kebab)

Linker data-linker-* ​

AttributeEffect
data-linker / -mode / -instance / -url / -min-delayThe mount point (produced by linker::mount; don't write by hand)
data-linker-callMethod name
data-linker-args'{"id":3}' / form / keyword,tab
data-linker-valueMerges the element's own value under this key
data-linker-extraFixed values, merged last
data-linker-onTriggering event
data-linker-debounceMilliseconds
data-linker-bindSeveral triggers (linker::bind)
data-linker-confirm / -danger / -title / -label / -targetConfirmation
data-linker-refresh-on-reconnectRefetch when the connection comes back
data-linker-ref-dom / -empty / -meta / -allow / -seeddom.repeat reference structure

PHP attributes → Rust ​

PHPRust
#[Computable]List the method name in const METHODS
#[Computable(cache: true)]Use the cache yourself, with context.user in the key
#[Validate([...])]Read args in call, validate, return LinkerResponse::validation([...])
#[RequiresAuth]The runtime always requires a login
#[RequiresVerified]Check yourself and return LinkerResponse::policy(messages::UNVERIFIED)
#[Authorize('ability', Model::class, arg: 'id')]Model::find_or_fail(id).await? + user.authorize(Policy::ability, &model).await?
allowsRefererUrls()const ALLOWS_REFERER_URLS: &[&str] = &["/orders/*"]
mode(): LinkerModeconst MODE: LinkerMode = LinkerMode::Stateless

LinkerComponent ​

APIEffect
const ALIASThe name the browser uses
const MODEStateful (default) / Stateless
const METHODSExposed methods
const ALLOWS_REFERER_URLSRestricts source pages (path wildcards)
async fn mount(&mut self, &LinkerContext, &Args)When an instance is created (Stateless can't have parameters)
fn booted(&mut self, &LinkerContext)Before every call
async fn call(&mut self, &LinkerContext, &str, Args)Dispatches methods
Struct fieldsServer-side state (written back on Stateful success)
LinkerResponse::ok().data(..)Success
LinkerResponse::validation / policy / not_found / failFailures
.then() / .catch() / .always()Pipeline

Events ​

Eventdetail
cg:state{ key, value, previous }
cg:rendered{ root, … }
cg:errorThe exception

Commands ​

bash
cargo test --workspace
python3 scripts/sync-php-assets.py ../CGWebFramework
grep -rn -A1 "const ALIAS\|const METHODS" src/cg
cargo run -- route:list