As I wrote above, save the tag in a variable that you return in your controller:
<?php
if(param('tag')) {
$tag = urldecode(param('tag'));
$articles = $pages->find('home')
->children()
->visible()
->filterBy('tags', $tag, ',')
$title = $tag;
}
if(param('color') {
$color = urldecode(param('color'));
$articles = $pages->find('home')
->children()
->visible()
->filterBy('colors', $color, ',')
$title = $color;
}
...
else {
//show all articles
}
return compact('articles', 'title');
?>
Then in your template:
<h1 class="title">Articles tagged with <mark><?php echo $title ?></mark></h1>
You should not put any html into your controller, it’s just for the logic and should return something, not echo anything.