---
title: "Feature: The replace view helper can return the number of edits"
manual: "Academic Projects"
version: "3.0"
permalink: "https://docs.typo3.org/permalink/fgtclb/academic-projects:feature-1785882300@3.0"
source: "Changelog/2.4/Feature-ReplaceViewHelperReturnCount.rst"
rendered: "2026-10-26T17:55:40+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. No template could therefore
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
<html xmlns:ap="http://typo3.org/ns/FGTCLB/AcademicProjects/ViewHelpers"
      data-namespace-typo3-fluid="true">
<ap:format.replace
    content="A research project of the research group"
    substring="research"
    replacement="teaching"
    returnCount="true"
/>
</html>
```

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.

## Affected Installations {#affected-installations}

Installations with templates that use the view helper. No action is required.

## References {#references}

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