Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Display data in template conditionally on field values


Reply


2 Posts   698 Views

Avatar
bostonmark

Community Member, 10 Posts

5 September 2011 at 8:08am

I have two fields in the back-end, an image field and a text area for YouTube embed code. I want to show the image field in the template only if the textarea has no value. I'm new to SS; my approach for this was to create a function in my page class to return a bool if the textrea has a value. On the front-end template I will access that bool in a conditional block like so:

<% if hasEmbedCode %>
$VideoEmbedCode
<% else %>
$PlaceholderImage
<% end_if %>

I'm not sure how to write the hasEmbedCode() function to return a bool based on the value of the Embed Code field.

Avatar
stallain

Community Member, 61 Posts

5 September 2011 at 10:28am

Edited: 05/09/2011 10:33am

Hello, you don't need to write a new function ; this code should work :

<% if VideoEmbedCode %>
$VideoEmbedCode
<% else %>
$PlaceholderImage
<% end_if %>


Stan