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.

General Questions /

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

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

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


Go to End


2 Posts   1199 Views

Avatar
Webdoc

Community Member, 349 Posts

20 March 2011 at 4:09am

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

Community Member, 349 Posts

20 March 2011 at 4:19am

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