SilverStripe: Rendering a userforms page type in a template loop

喜欢而已 提交于 2020-01-02 18:04:30

问题


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?


回答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.



来源:https://stackoverflow.com/questions/30404467/silverstripe-rendering-a-userforms-page-type-in-a-template-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!