Changing a menu link used in the sitemap module but not in main nav We are using the Sitemap module for creating a sitemap generated from three menus (Footer, Main nav and a 3rd arbitrary one).

In the main nav we have a placeholder LI element which we use to insert a view.

In the sitemap template we need to replace this placeholder with some content without affecting the main nav.

In the sitemap overridden template where {{ item.content }} normally appears I tried replacing with the following:

{{ item.content|replace('&gt;LRGPH_BRANCHES_BY_SERVICE&lt;', ('&gt;' ~ allBranches ~ '&lt;')) }}


Note: allBranches is a concatenation of the output of 4 views (Essentially pure HTML)

but Twig/Drupal seems to have issue with this as I get an error, as per below:


  Warning: strtr() expects parameter 1 to be string, array given in twig_replace_filter() (line 521 of /var/www/vendor/twig/twig/src/Extension/CoreExtension.php).
      twig_replace_filter(Array, '&gt;LRGPH_BRANCHES_BY_SERVICE&lt;', '&gt;


I next tried using the contributed modules hook, namely function TEMPLATE_preprocess_sitemap(&amp;$variables) but although I can see the HTML output of the sitemap I cannot change it using this as far as I can tell.

Is there any way to achieve this change at all without altering the Main navigation?
{{ something.content }} is a render array, you can't do a string replace on an array. But you can store the computed string output of the render array, and do a string replace on the rendered output:

{# compute the output of the render array and store it #}
{% set rendered_html_string = item.content|render %}

{# do the replacement #}
{% set modified_string = rendered_html_string|replace('seachtext', 'replacetext') %}

{# print the modified string #}
{{ modified_html_string }}