Views remove link to content based on publication status Drupal 8. I have a list of images that link back to a content page. If the page is unpublished I want to remove the link. 

So far I've set up a hook_post_render that checks the publication status. The only way I can think to move forward is to make make the view put out a link as a separate field, then conditionally remove the value. I don't love it and I'd rather jump in to where views is wrapping the image.
With Views's support for Twig, you can now implement conditional hyperlinking without any hook modification to your view. 


Add a Content: Path field to your view with Exclude from display checked.
Add a Content: Publishing status field to your view with Exclude from display checked, using the True/False Output format.
Add a Image (field_my_image_field:target_id) relationship to your view that targets your specific image.
Add a File: URI field to your view with the Exclude from display checked, using the File URI as the Formatter, and the Display the file download URI checked.
Finally, add a Global: Custom field with custom Twig that can check the publishing status value for displaying the link and use the excluded fields as replacement patterns.


For example:

{% if status == 'True' %}
&lt;a href="{{path}}"&gt;
  &lt;img src="{{uri}}" /&gt;
&lt;/a&gt;
{% else %}
  &lt;img src="{{uri}}" /&gt;
{% endif %}