Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » How to formulate <% if $File %>

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

Page: 1
Go to End
Author Topic: 660 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    How to formulate <% if $File %> Link to this post

    Hello,

    I am wondering how to formulate the following:

    I am using uploadify to upload files, and it works, but now in template i need the <% if $File %> as in If $File is uploaded then show sth, if not don't

    how would you do it? Asking cause

                   <% if $Rezultati %>
                      <p>Rezultati izazova:</p>
                      <p>&nbsp;<a href="$Razultati.URL">Rezultati</a></p>
                   <% end_if %>

    $Rezultati being the $File, doesn't work

    EDIT:

    Been trying with return file_exists($this->Rezultati); in some function but it doesn't work also, always returns bool(false) so I rly don't know how to check if there is a file uploaded or not.

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: How to formulate <% if $File %> Link to this post

    For <% if %> you don't need to include the $ symbol i.e <% if Rezultati %>

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: How to formulate <% if $File %> Link to this post

    Yes, I have tried that, but for some reason that ALWAYS returns false value (even for one test challenge i uploaded sth in $Rezultati) and the text inside <% if %> , along with download link for the $Rezultati file is never displayed.

    EDIT:

    Been trying with return file_exists($this->Rezultati); in some function but it doesn't work also, always returns bool(false) so I rly don't know how to check if there is a file uploaded or not.

    EDIT2:

    works, had a typo in filename

  • mayko
    Avatar
    Community Member
    3 Posts

    Re: How to formulate <% if $File %> Link to this post

    You should be able to test if a file exist by addin ID to the Object.
    Please try (untested):

    <% if RezultatiID %>
    <p>Rezultati izazova:</p>
    <p>&nbsp;<a href="$Razultati.URL">Rezultati</a></p>
    <% end_if %>

    660 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.