Check if the `request` variable isn't nil when calling render_to_string

closes #14125