---
title: "Feature: The replace view helper can return the number of edits"
manual: "Academic Projects"
version: "main"
source: "Changelog/2.4/Feature-ReplaceViewHelperReturnCount.rst"
rendered: "2026-09-22T20:39:25+00:00"
---

# Feature: The replace view helper can return the number of edits {#feature-1785882300}

## Description {#description}

`FGTCLB\AcademicProjects\ViewHelpers\Format\ReplaceViewHelper` counted its
replacements and returned the count instead of the replaced content when a
`returnCount` argument was set:

```php
if ($this->arguments['returnCount'] ?? false) {
    return $count;
}
```

That argument was never registered, and Fluid rejects an argument a view helper
does not declare while it parses the template - so no template could reach the
branch:

```text
Undeclared arguments passed to ViewHelper
FGTCLB\AcademicProjects\ViewHelpers\Format\ReplaceViewHelper: returnCount.
Valid arguments are: content, substring, replacement, caseSensitive
```

`returnCount` is a registered boolean argument now, defaulting to `false`:

```html
<ap:format.replace
    content="A research project of the research group"
    substring="research"
    replacement="teaching"
    returnCount="true"
/>
```

renders `2`.

## Impact {#impact}

Nothing changes for a template that does not pass the argument - the default
returns the replaced content, as before. A template that passed `returnCount`
used to raise the parse error above and renders the count now.

The count is the one `str_replace()` and `str_ireplace()` report, so it counts
occurrences rather than distinct substrings, and it is `0` for a substring that
does not occur.

## References {#references}

-   [str_replace](https://www.php.net/manual/en/function.str-replace.php) \-
    the `$count` parameter this returns.
