Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » (solved)How to random include files (in include folder)

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

Page: 1
Go to End
Author Topic: 772 Views
  • Webdoc
    Avatar
    Community Member
    332 Posts

    (solved)How to random include files (in include folder) Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: (solved)How to random include files (in include folder) Link to this post

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

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