2

Using SilverStripe 3.1 I have laid out a FrontPage page type that loops through its children to produce a big tall scrolling page. It has all kinds of different page types in it and I access their templates by creating their controllers on the fly by adding on to the Page class:

class Page extends SiteTree {

    .....

    function RenderAsChild($templateName = null) {
        if(!$templateName) $templateName = $this->ClassName;
        if(!$this->pageController){
            $class = $this->ClassName . "_Controller";
            $this->pageController = new $class($this);
        }
        return $this->pageController->renderForHolderPage($templateName);
    }

and in the controller:

class Page_Controller extends ContentController {

....

    function renderForHolderPage($templateName = null) {
        if(!$templateName) $templateName = $this->ClassName;
        return $this->renderWith(array($templateName));
    }

In this way I can render pages and manage their templates and special features easily while still treating them all the same way in the template, something like:

    <% loop $Children %>
        <% if $ClassName = 'FancyPage' %>
            $RenderAsChild
......

The thing is I want to use the userforms extension this way but in the template in a loop or control it shows up just as a page. It does not appear to know anything about the form or the UserDefinedForm object.

Is there a way to get userforms to render as a child in a template?

NFG
  • 639
  • 1
  • 5
  • 15
  • Possible duplicate of [Silverstripe Multiple Userforms on one page](http://stackoverflow.com/questions/34888010/silverstripe-multiple-userforms-on-one-page) – Turnerj Jul 18 '16 at 02:47

1 Answers1

1

Did a quick and dirty test and it seems to work only when you have

$Form 

in the theme file

It wont replace the $UserDefinedForm as it´s not invoking the render with the index() that has the necessary scrips to replace $UserDefinedForm bit as far as I can tell.

Olli Tyynelä
  • 586
  • 3
  • 14
  • Actually what I did was I created a separate page template called BasicPage.ss and forced the Page class to render to that using the method above. That worked, but not all the javascript parts got included which tells me I am still doing it wrong. – NFG May 26 '15 at 18:45
  • You can add those js inclusions manually for now to your main template https://github.com/silverstripe/silverstripe-userforms/blob/master/code/model/UserDefinedForm.php#L447 – Olli Tyynelä May 27 '15 at 06:22
  • why the javascripts are missing: we are just missing the necessary place on the template for SS to render the data or the more plausible thing: as the controller render is i invoked without the right the logical order: init / index it won't do all the necessary bits > find a way to do that OR do it the quick and dirtyway just add the js requirements manually if its just the userfom that you have to worry about – Olli Tyynelä May 27 '15 at 06:29
  • I am pretty sure that this is all correct. The combination of a subclass and overriding the init() function with a test for something like is_a('UserDefinedForm') and the inclusion of the js FinBoWa linked above this can be made to work. I have not yet put it all to the test though. – NFG Jun 05 '15 at 15:51