drupal-render
Skill71 starsChanged 7 months agoMITView on GitHub
Drupal render arrays — structure, cache metadata (tags, contexts, max-age), render elements, and markup safety.
In this repository35 other files it gives its agents.
- ddev-expertSkill
- docker-localSkill
- drupal-accessSkill
- drupal-cachingSkill
- drupal-composerSkill
- drupal-configSkill
- drupal-contrib-mgmtSkill
- drupal-debuggingSkill
- drupal-drushSkill
- drupal-dttSkill
- drupal-entity-apiSkill
- drupal-eventsSkill
- drupal-fieldsSkill
- drupal-form-ajaxSkill
- drupal-form-alterSkill
- drupal-form-apiSkill
- drupal-form-validationSkill
- drupal-hooksSkill
- drupal-htmxSkill
- drupal-javascriptSkill
- drupal-kernelSkill
- drupal-menusSkill
- drupal-migrationsSkill
- drupal-paragraphsSkill
- drupal-pluginsSkill
- drupal-queriesSkill
- drupal-routesSkill
- drupal-search-apiSkill
- drupal-securitySkill
- drupal-servicesSkill
- drupal-stateSkill
- drupal-taxonomySkill
- drupal-twigSkill
- drupal-unitSkill
- SKILL.mdSkill
The file
Files
Drupal Render Arrays
Basic Structure
$build = [
'#type' => 'container',
'#attributes' => ['class' => ['my-wrapper']],
'content' => [
'#markup' => $this->t('Hello world'),
],
];Cache Metadata (Always Required)
$build['content'] = [
'#markup' => $output,
'#cache' => [
'tags' => ['node:' . $node->id(), 'node_list'],
'contexts' => ['user.permissions', 'url.query_args'],
'max-age' => 3600,
],
];Cache Tag Conventions
| Tag | Invalidates when |
node:123 | Node 123 is saved |
node_list | Any node is created/deleted |
user:456 | User 456 is saved |
taxonomy_term:789 | Term 789 is saved |
config:my_module.settings | Config is saved |
block_content:1 | Block content is saved |
Cache Contexts
| Context | Varies by |
user | Current user identity |
user.permissions | User's permissions |
user.roles | User's roles |
url | Full URL |
url.path | URL path only |
url.query_args | Query string |
languages | Current language |
session | Session data |
theme | Active theme |
Markup Safety
// Plain text — always safe
$build['#plain_text'] = $user_input;
// Trusted markup — use Markup class
use Drupal\Core\Render\Markup;
$build['#markup'] = Markup::create('<strong>Safe</strong>');
// User input in markup — filter first
use Drupal\Component\Utility\Xss;
$build['#markup'] = Markup::create(Xss::filter($user_input));
// Admin-level markup — allows more tags
$build['#markup'] = Markup::create(Xss::filterAdmin($html));Render Elements
// HTML tag
$build['heading'] = [
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $this->t('Title'),
'#attributes' => ['class' => ['my-heading']],
];
// Link
$build['link'] = [
'#type' => 'link',
'#title' => $this->t('Go'),
'#url' => Url::fromRoute('entity.node.canonical', ['node' => $nid]),
'#attributes' => ['class' => ['button']],
];
// Entity view
$build['node'] = $this->entityTypeManager
->getViewBuilder('node')
->view($node, 'teaser');
// Inline template
$build['inline'] = [
'#type' => 'inline_template',
'#template' => '<div class="{{ class }}">{{ content }}</div>',
'#context' => ['class' => 'my-class', 'content' => $content],
];Lazy Builder (Uncacheable Content)
$build['dynamic'] = [
'#lazy_builder' => [
'my_module.service:buildDynamicContent',
[$arg1, $arg2],
],
'#create_placeholder' => TRUE,
];Rendering Programmatically
// Inject renderer service
public function __construct(
private readonly RendererInterface $renderer,
) {}
// Render to string
$html = $this->renderer->render($build);
// Render in isolated context (doesn't bubble cache)
$html = $this->renderer->renderInIsolation($build);Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

