How can I render out a public page from admin?
Created 7 years ago by daviesgeek

I want to render a public page from the admin end of things, but I'm running into all sorts of trouble doing so. I basically copied the functionality from LoadCurrentTheme.php like so:

In my controller's constructor:

$this->themes     = $themes;
$this->config     = $config;
$this->asset      = $asset;
$this->manager    = $manager;
$this->view       = $view;
$this->image      = $image;
$this->translator = $translator;

$standard = $this->themes->get($this->config->get('streams::themes.standard'));
$admin    = $this->themes->get($this->config->get('streams::themes.admin'));


if ($theme = $this->themes->current()) {
  $this->view->addNamespace('theme', $theme->getPath('resources/views'));
  $this->translator->addNamespace('theme', $theme->getPath('resources/lang'));

  $this->asset->addPath('theme', $theme->getPath('resources'));
  $this->image->addPath('theme', $theme->getPath('resources'));
$page = $pages->find(1);


$type    = $page->getType();
$handler = $type->getHandler();

$template->set('page', $page);


$htmlString = $page->getResponse()->getContent();

// Do stuff here

return $page->getResponse();

The problem is that the theme isn't set correctly and the assets are not loading correctly. I get this error:

"Asset [<pyro-path>/core/pyrocms/starter-theme/resources/less/fonts/fonts.less] does not exist!" in "theme::partials/metadata"

Somehow it's trying to load the wrong partials/metadata, which causes the fonts.less file to attempt to be loaded, and it fails. It seems to me like I need to unset something with Assetic, but I'm not sure. Any suggestions?

ryanthompson  —  7 years ago

I think the only way to really do this is either use frames and load the page outside of the "admin" URL. The segment_1 == admin logic is what switching the themes out.

Your second alternative is to not rely on 'theme' if possible. Reference the theme directly with it's full dot namespace.

daviesgeek  —  7 years ago

Hmm okay. Frames won't exactly work, since I'm attempting to write the page to disk and cache it on S3.

The second alternative might be better, but I think I'm going to take an alternative approach to this solution.

daviesgeek  —  7 years ago
  • Frames won't work without a lot of crazy hacks to fetch the page.
adnan  —  7 years ago

Have you succeeded? I'd be interested to hear the scenario for this requirement!

The closest I got to needing something unconventional to how Pyro does thing is to have Modules with built-in themes, I needed that for a theme-able Survey Module,

Finally, if I were to have that need, I would have tried to override the route in question and use a standard controller,