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

include php file


6 Posts   2742 Views


14 July 2010 at 3:49am (Last edited: 14 July 2010 6:34pm), Community Member, 192 Posts

I create a new page php (ArticlePage.php) whti some function and a relative template (
Is it possible include this new page in a parte of an othe page (for example Page.php)?

something like..

<% include ArticlePage %>

I need create a table in and in every block of my table a different include with different template. Every new tempate is caracterized by different php code.
I hope to be clear..



14 July 2010 at 6:34pm Community Member, 192 Posts

any idea?is possible?


14 July 2010 at 7:12pm Forum Moderator, 5511 Posts

If you want to control content from another page you can use the <% control Page(url-of-your-page %>.... $Title ... <% end_control %> which will control over the page object with the given URL. If control Page() doesn't work then you will have to write a PHP function to render the template inside the page (see documentation about renderWith()). Also you can only use <% include %> to get templates from the includes folder (not from layout folder).


14 July 2010 at 8:05pm (Last edited: 14 July 2010 9:06pm), Community Member, 192 Posts

Thanks for reply me but for me is a bit complicated..can you help me to set code?

This is my ArticlePage.php

class ArticlePage extends Page {
   public static $db = array();
   public static $has_one = array();

class ArticlePage_Controller extends Page_Controller {
   public function init() {
      Requirements::themedCSS("form"); }
   function templatePhp() {

return $_return_article;}   

$doSet = new DataObjectSet();
    $result = array(
    'data' => $_return_hitlist, );
    $doSet->push(new ArrayData($result));
return $doSet;

classe.php file set articlePhp(); function.
To show my $_return_article variable in template a write $data but i see nothing but var_dump($doSet) is


14 July 2010 at 9:12pm Community Member, 215 Posts

"How can I show my $_return_article variable in template?"

ArticlePage extends Page so templatePhp() does not exist per se in
- You can call templatePhp() with $templatePhp in if you want to.
- Or use <% control Page(url-of-your-page) %>$templatePhp<% end_control %> or <% if ClassName = ArticlePage %>$templatePhp<% end_if %> in
- Or create a wrapper method in Page.php for ArticlePage.php (or move templatePhp() to Page.php of course)


14 July 2010 at 10:00pm Community Member, 192 Posts

Thanks!!I use last solution..the second don't work..