Jump to:

23369 Posts in 18145 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » include php file

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: 2563 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    include php file Link to this post

    Hi!
    I create a new page php (ArticlePage.php) whti some function and a relative template (ArticlePage.ss).
    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 Page.ss 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..

    Thanks!

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: include php file Link to this post

    any idea?is possible?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: include php file Link to this post

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

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: include php file Link to this post

    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() {
          parent::init();
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form"); }
       
       function templatePhp() {
        require_once('../class/classe.php');

    $_return_article=articlePhp();
    return $_return_article;}   

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

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

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: include php file Link to this post

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

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

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: include php file Link to this post

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

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