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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

How to formulate <% if $File %>


Go to End


4 Posts   2036 Views

Avatar
Mackodlak

Community Member, 95 Posts

13 September 2011 at 10:38pm

Edited: 14/09/2011 1:16am

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.

Avatar
Willr

Forum Moderator, 5523 Posts

13 September 2011 at 10:46pm

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

Avatar
Mackodlak

Community Member, 95 Posts

13 September 2011 at 11:47pm

Edited: 14/09/2011 1:46am

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

Avatar
mayko

Community Member, 3 Posts

3 November 2011 at 12:55pm

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 %>