Skip to content
Skills Library
Programming · Building & coding

structure-content

/structure-content

Slice management in REDAXO – the content blocks that make up an article. Use when the user creates/edits/deletes slices programmatically, lists slices of an article, copies content between articles, or syncs content between languages.

Licence
MIT
Last repository change
20.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 20.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Slice management in REDAXO – the content blocks that make up an article. Use when the user creates/edits/deletes slices programmatically, lists slices of an article, copies content between articles, or syncs content between languages.

Original author description

Slice management in REDAXO – the content blocks that make up an article. Use when the user creates/edits/deletes slices programmatically, lists slices of an article, copies content between articles, or syncs content between languages.

How it works

  1. Reading a slice
  2. Listing slices of an article
  3. Adding a slice programmatically
  4. Editing / deleting
  5. Moving (re-ordering)
  6. Cloning content between languages
  7. Copy a whole article
  8. Rendering article content from PHP
  9. Common pitfalls
Original SKILL.md headings · 170 lines, 774 words
SKILL.md preview
---
name: structure-content
description: Slice management in REDAXO – the content blocks that make up an article. Use when the user creates/edits/deletes slices programmatically, lists slices of an article, copies content between articles, or syncs content between languages.
---

# Slices & Article Content

Article content in REDAXO consists of "slices" – ordered instances of modules with their `REX_VALUE` / `REX_MEDIA` / `REX_LINK` data filled in. Slices are stored in `rex_article_slice`.

For most use cases, you don't manipulate slices directly – the backend UI handles it. The API matters when:

- Importing content from external sources
- Cloning or templating content across articles
- Building custom workflows (e.g. duplicate to all languages)

## Reading a slice

`rex_article_slice` provides one slice at a time:

```php
$slice = rex_article_slice::getArticleSliceById($sliceId, $clangId);
echo $slice->getModuleId();
echo $slice->getValue(1);   // REX_VALUE[1]
echo $slice->getMedia(1);   // REX_MEDIA[1] – returns filename string
echo $slice->getMedialist(1); // comma-separated filenames
echo $slice->getLink(1);    // REX_LINK[1] – article ID as string
echo $slice->getLinklist(1);
```

## Listing slices of an article

```php
$slices = rex_article_slice::getSlicesForArticle($articleId, $clangId);
foreach ($slices as $slice) {
    echo "Slice #{$slice->getId()} module #{$slice->getModuleId()}\n";
}
```

## Adding a slice programmatically

Use `rex_content_service::addSlice()` so the priority shift, cache invalidation, and `SLICE_ADDED` extension point all happen.

```php
$articleId = 42;
$clangId   = rex_clang::getCurrentId();
$ctype     = 1;  // content area (templates may define multiple)
$moduleId  = 7;

$data = [
    'value1' => 'Hello world',
    'value2' => 'Some longer text',
    'media1' => 'hero.jpg',
    'link1'  => '5',
];

// addSlice() returns a status message, not the ID – capture the ID from SLICE_ADDED
$sliceId = null;
rex_extension::register('SLICE_ADDED', static function (rex_extension_point $ep) use (&$sliceId): void {
    $sliceId = (int) $ep->getParam('slice_id');
});

rex_content_service::addSlice($articleId, $clangId, $ctype, $moduleId, $data);
if (null === $sliceId) {
    throw new RuntimeException('SLICE_ADDED did not fire – addSlice() failed or capturing code changed');
}
```

The `$data` keys are `value1`–`value20`, `media1`–`media10`, `medialist1`–`medialist10`, `link1`–`link10`, `linklist1`–`linklist10`.

Modules do not have to start at `value1` – the YForm Formbuilder module, for example, keeps its form definition in `value3`. Tooling that walks slices (export, search, migration) must cover all twenty `value` slots plus the media and link columns, or it silently misses content.

## Editing / deleting

There is no `rex_content_service::editSlice()`. The backend content page writes the row with `rex_sql` (and fires `SLICE_UPDATED`); the minimum is the update plus clearing the article cache:

```php
$sql = rex_sql::factory();
$sql->setTable(rex::getTable('article_slice'));
$sql->setWhere(['id' => $sliceId]);
$sql->setValue('value1', 'Updated headline');
$sql->addGlobalUpdateFields();
$sql->update();
rex_article_cache::delete($articleId, $clangId);

rex_content_service::deleteSlice($sliceId);
```

## Moving (re-ordering)

```php
rex_content_service::moveSlice($sliceId, $clangId, 'moveup');   // or 'movedown'
```

Any other direction throws `rex_exception`; moving the first slice up or the last slice down throws `rex_api_exception`.

For exact priority on a new slice, pass `priority` in `$data` to `addSlice()` – it re-sorts the siblings. An existing slice has no service method for an exact priority; move it step by step:

```php
$slice = rex_article_slice::getArticleSliceById($sliceId, $clangId);
$target = 3;
$direction = $slice->getPriority() > $target ? 'moveup' : 'movedown';
for ($i = abs($slice->getPriority() - $target); $i > 0; --$i) {
    rex_content_service::moveSlice($sliceId, $clangId, $direction);
}
```

## Cloning content between languages

Common workflow: "create a German article, then duplicate its slices into the English variant for translation".

```php
function copySlicesAcrossClang(int $articleId, int $fromClang, int $toClang): void
{
    $slices = rex_article_slice::getSlicesForArticle($articleId, $fromClang);
    foreach ($slices as $slice) {
        $data = [
            'priority' => $slice->getPriority(),
        ];
        for ($i = 1; $i <= 20; $i++) {
            $data['value' . $i] = $slice->getValue($i);
        }
        for ($i = 1; $i <= 10; $i++) {
            $data['media' . $i]     = $slice->getMedia($i);
            $data['medialist' . $i] = $slice->getMedialist($i);
            $data['link' . $i]      = $slice->getLink($i);
            $data['linklist' . $i]  = $slice->getLinklist($i);
        }
        rex_content_service::addSlice(
            $articleId,
            $toClang,
            $slice->getCtype(),
            $slice->getModuleId(),
            $data
        );
    }
}
```

## Copy a whole article

`rex_article_service::copyArticle()` clones the article record only. To clone with content, follow up with `rex_content_service::copyContent()`:

```php
$newId = rex_article_service::copyArticle($sourceId, $targetCategoryId);
rex_content_service::copyContent($sourceId, $newId, $clangId, $clangId);
```

## Rendering article content from PHP

Inside templates, use `REX_ARTICLE[]`. Outside (e.g. cron job, CLI), use `rex_article_content`:

```php
$content = new rex_article_content($articleId, $clangId);
$content->setTemplateId(0); // 0 = no template wrapper
$html = $content->getArticle();
```

This is how RSS-feed addons, search indexers, and PDF exporters extract article HTML.

## Common pitfalls

- Inserting slices via raw SQL – misses `priority` shifting and cache flush, leading to broken ordering and stale cached pages.
- Forgetting `ctype` – defaults to 1, which works only if your template defines a single content area.
- Hardcoding module IDs in code – they differ between staging and production. Look them up by name on first run and cache:

```php
$sql = rex_sql::factory();
$sql->setQuery('SELECT id FROM ' . rex::getTable('module') . ' WHERE name = ?', ['Hero banner']);
$moduleId = $sql->getRows() ? (int) $sql->getValue('id') : null;
```

- Using the return value of `addSlice()` as the slice ID – it is a status message (`string`). Get the ID from the `SLICE_ADDED` extension point (param `slice_id`). `rex_extension` has no unregister, so register the listener once, not per call.
- Calling `getValue(0)` instead of `getValue(1)` – placeholders are 1-indexed.

Versions

The database has no other skills named structure-content.

Database snapshot: 13.11.2026 · package version afad6b36e559 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100redaxo-templates
    REDAXO template authoring – page layouts that wrap article content. Use when the user creates or edits a template, asks about getArticle(), works with rex_fragment, sets up multi-language output, or wants to embed slices into a layout.
  • 100structure-articles
    Working with REDAXO articles via rex_article – fetching, listing, status, dates, URLs, and the start/notfound/site articles. Use when the user reads or modifies article data, builds article lists for templates, queries the structure tree, or handles per-language article variants.
  • 100go-data-structures
    Use when working with Go slices, maps, or arrays — choosing between new and make, using append, declaring empty slices (nil vs literal for JSON), implementing sets with maps, and copying data at boundaries. Also use when building or manipulating collections, even if the user…
  • 100implement-fleet
    Orchestrator-workers variant of implement-approved-slice that runs independent approved slices in parallel, one worktree-isolated worker per slice per wave, merged after each wave. Use when the active task has an approved multi-slice plan whose Execution waves show at least one…
  • 90convert-code
    Converts code between programming languages while preserving logic, error handling, and idiomatic patterns. Use when migrating modules between languages or frameworks.
  • 90build-slice
    Build ONE vertical slice of an approved feature design. First agree the code-level implementation choices with the user, then write and get approval for a code-level slice plan (slices/slice-N.md), then build test-first, following the plan exactly, with verification,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.