I am trying to make my code more efficient.
I use EJS code.
What I have now…
<%if(post.alpha){%>
<a target="_blank" href="<%- post.alpha %>">
</a>
<%}%>
<%if(post.beta){%>
<a target="_blank" href="<%- post.beta%>">
</a>
<%}%>
<%if(post.gamma){%>
<a target="_blank" href="<%- post.gamma %>">
</a>
<%}%>
What the above code says is:
“If there is ALPHA then link points to ALPHA”.
“If there is BETA then link points to BETA”.
This works.
But to make this more clean and lean, I was thinking something like this…
<%if(post.alpha || post.beta || post.gamma){%>
<a target="_blank" href="<%- post.alpha %>" || <%- post.beta %>" ||
<%- post.gamma %>">
</a>
<%}%>
What the above is supposed to say is:
“If there is ALPHA or BETA or GAMMA, the link to ALPHA or BETA or GAMMA”.
I put this code block in the section within another IF-statement. So it will only find one variable (either ALPHA, or BETA or GAMMA), that works.
The only problem is in the HREF, there it does not work, because it has to select the ALPHA HREF when the IF statement finds ALPHA, and it has to select the BETA HREF when the IF statement finds BETA, etc etc.
Is my idea possible in some way? In my “idea” code block, I just need for the HREF to make ALPHA correspond to ALPHA, BETA to BETA etc.