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

(solved)How to random include files (in include folder)


Reply

2 Posts   779 Views

Avatar
Webdoc

20 March 2011 at 4:09am Community Member, 332 Posts

Hi what function do i need to write into Page.php and how to add it on template if i wanna randomly include .ss files from include folder named 1.ss, 2.ss, 3.ss, 4.ss, 5.ss, 6.ss .

Tryed:
in Page.php:
function RandomNumber() {
return rand(1, 6);
}

and

in Page.ss:
<% include $RandomNumber %>

but it didnt work just saw in template after flushing : <% include 4 %> but it didnt call the including just generated text like so where i was going wrong

Avatar
Webdoc

20 March 2011 at 4:19am Community Member, 332 Posts

so it works: if i use the page.php as it is

<% if RandomNumber == 1 %>
<% include 1 %>
<% else_if RandomNumber == 2 %>
<% include 2 %>
<% else_if RandomNumber == 3 %>
<% include 3 %>
<% else_if RandomNumber == 4 %>
<% include 4 %>
<% else_if RandomNumber == 5 %>
<% include 5 %>
<% else_if RandomNumber == 6 %>
<% include 6 %>;
<% end_if %>