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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[Solved] renderWith not pulling from theme templates only from mysite templates


Go to End


5 Posts   1683 Views

Avatar
mi32dogs

Community Member, 75 Posts

31 July 2015 at 4:57pm

Edited: 31/07/2015 4:58pm

Hi,
I seem to have some trouble with the renderWith function

I have a DataObject and I created a public function that renders some data into a template and then returns the HTML, so I can use it to insert it in the TinyMCE via a widget.

public function getEventBlock()
{
      return $this->renderWith('Includes/EventBlock');
}

It works if I put the template in the mysite templates directory, but I like it to pull the template from the theme dir, so it will work with different themes.

I tried to use the full path the theme dir but that does not work
I tried this

public function getEventBlock()
{
$Template = new SSViewer();
$Template->setTemplateFile('themes/MyTheme/templates/Includes/EventBlock.ss');
return $this->renderWith($Template);
}

Any tips on how I can do this would be appreciated.

Avatar
Pyromanik

Community Member, 419 Posts

31 July 2015 at 11:39pm

If you're trying to do this from the CMS, it won't work because the CMS has no theme.

Avatar
mi32dogs

Community Member, 75 Posts

3 August 2015 at 4:21am

thanks Pyromanik, Your right, if I call it from a template it is working fine.

But is there no way I can give it the full path to the template I want to use?

Avatar
Pyromanik

Community Member, 419 Posts

3 August 2015 at 11:06pm

Avatar
mi32dogs

Community Member, 75 Posts

11 August 2015 at 7:36am

No, just adding the .ss behind it did not work, but i found a solution, first you have to switch on the theme in SSViewer and than you assign the theme you like to the SSViewer that works

  public function getEventBlock()
  {
    Config::inst()->update('SSViewer', 'theme_enabled', true);
    Config::inst()->update('SSViewer', 'theme', 'MyTheme');
    $Template = new SSViewer('Includes/EventBlock');
    return $Template->process($this);
  }