Twig: How to show static text in the template to the Anonymous User? On a Drupal 8.9.13 website, I've removed the permission &quot;View published content&quot; from the Anonymous user.
By default, when someone visits the front page, Drupal will then display:

Access deniedYou are not authorized to access this page.

I want to replace this with some other text, e.g.

Please create an account to see our content.

To do this I try to create something like this in page--front.html.twig.
{% if not logged_in %}
&lt;p&gt;Please create an account to see our content.&lt;/p&gt;
{% endif %}

However, I am stuck .

I am not able to get rid of the &quot;Access denied&quot; text for the anonymous user.
I can't get the the text &quot;Please create an account to see our content.&quot; to show for the Anonymous user.  (If I remove &quot;not&quot; from the if-test it shows up as expected on the front page for the Authenticated user).

The site's theme is an otherwise unmodified subtheme of Bootstrap Barrio 5.1.4, but I don't think the problem is theme-dependent. Rather, the problem is that I don't understand the interplay between Twig and permissions (IMHO, there should be none).
Add a page--403.html.twig template to your theme.
See this change record: https://www.drupal.org/node/2960810
If you only want to change the default message you don't need a template. You can configure a node as access denied message in /admin/config/system/site-information.
Caveat for the non-template solution (as commented by @FreeRadical): If you restrict access to all nodes you have to find a different type of content. Could be a small module providing a custom controller which returns the static text.
BTW the themed page--403.html.twig is built in a subrequest which only job is to return a themed page with blocks. It's too late to make decisions on what to do with a 403 exception at this point. If you want to replace the core handling of a 403 exception (returning a themed subrequest) use an exception subscriber with default priority. See https://drupal.stackexchange.com/a/245211/47547