You have placed your additions to the template after the closing bracket for the statement in the template that should have contained them.
Had you put your actual code in your comment instead of a screenshot I could have put a corrected version up for you to use.
Instead here is an example from my config for you.
{% set ignore_seconds = 60 %}
{% set ignored = state_attr('group.ignored_unavailable_entities', 'entity_id') %}
{% set ignore_ts = (now().timestamp() - ignore_seconds) | as_datetime %}
{% set entities = states
| rejectattr('domain', 'in', ['button', 'device_tracker', 'event', 'group', 'input_button', 'input_text', 'scene'])
| rejectattr('entity_id', 'in', integration_entities('browser_mod'))
| rejectattr('entity_id', 'in', integration_entities('hassio'))
| rejectattr('entity_id', 'in', integration_entities('dlna_dmr'))
| rejectattr('entity_id', 'contains', 'jason_laptop_media_player')
| rejectattr('entity_id', 'contains', 'jason_phone_media_player')
| rejectattr('entity_id', 'contains', 'jason_tablet_media_player')
| rejectattr('entity_id', 'contains', 'charlie_crate_camera')
| rejectattr('entity_id', 'contains', 'living_room_camera')
| rejectattr('entity_id', 'search', 'jphone_app|jtablet_app|jlaptop_chrome|jwork_chrome
|_dlna|_timers|_alarms|_next_alarm|sensor.daily_energy_consumption')
| rejectattr('last_changed', 'ge', ignore_ts) %}
{% set entities = entities | rejectattr('entity_id', 'in', ignored) if ignored != none else entities %}
{{ entities | map(attribute='entity_id') | reject('has_value') | list | sort }}
You also should test your templates in Developer Tools template editor to see if they evaluate as expected before putting them in your configuration.
Additionally, if you are only editing a template, only need to reload templates. You don’t need to reload your entire YAML config.
Hope this all helps!