Thread tagged as: Question

Hide if unused

Hi all,

I currently have the template for a job vacancy as follows:

<div style="padding-top: 10px">

    <img style="height: 100%; width: 100%; object-fit: contain" src="<perch:content type="image" id="image" label="Image" order="1" />" />

    <h3><perch:content type="text" id="job_title" label="Job Title" order="2" required="true"/></h3>

    <p style="min-height: 80px" align="justify"><perch:content type="textarea" id="description" label="Description" order="3" required="true"/></p>

    <div style="display: inline-block">
    <a class="<perch:content type="text" id="class" label="Class" order="5"/>" href="<perch:content id="file" type="file" label="File" order="6"/>" target="_blank"><perch:content type="text" id="desc" label="Button Text" order="4"/></a>

    <div style="display: inline-block">
    <a class="<perch:content type="text" id="class2" label="Class" order="8"/>" href="<perch:content id="file2" type="file" label="File" order="9"/>" target="_blank"><perch:content type="text" id="desc2" label="Button Text" order="7"/></a>


Now, this template used to only show the img tag when an image was uploaded. Now it shows it all the time, but obviously if no image is there is shows the placeholder default. Is there a way that I can hide this and only show it when an image is uploaded in Perch admin?

Conor Harkins

Conor Harkins 0 points

  • 3 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Just wrap the whole <img... /> line in if tags

<perch:if exists="image">
...img line...

Doh! Thanks man!