Jump to:

3447 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » If variable is blank

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

Page: 1
Go to End
Author Topic: 2023 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    If variable is blank Link to this post

    Hi everyone,

    I am building a site right now, that has a place for a user to enter custom content into their sidebar. This content shows up inside a custom div, with a background image.

    Is there a way, inside my templates, that I can essentially say "only if this content has been entered in the CMS (field is not blank/not NULL), than show this variable, else, ignore it?"

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: If variable is blank Link to this post

    Nevermind, I figured this out. For anyone else who may need this, here is the code, assuming you're working with the variable called SidebarContent

    <% if SidebarContent %>$SidebarContent<% end_if %>

    Notice that the <% if SidebarContent %> does not contain a dollar sign ($), this is what was messing me up.

    2023 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.