Jump to content

Calling Pages CSS from template?


Recommended Posts

I know how to dynamically add CSS saved as part of the theme. 

{{\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'something.css', 'someapp', 'front' ) );}}

But how can I do the same for Pages CSS files created at ACP → Pages → Templates → CSS?
Anyone knows?

Link to comment
Share on other sites

To put this in perspective: I have a Pages database where each record needs to get its own CSS. So far, I created those files in ”Theme → cms → front → custom” but IPS has removed that ability with 4.7. So now I need an alternative way to create and call custom CSS from a template. 

Link to comment
Share on other sites

If you know the ID of each CSS file you can do this

{{$key = 10;}}
{{$css = NULL; try { $css = (string) \IPS\File::get( 'cms_Pages', \IPS\cms\Templates::load( $key )->_file_object )->url; } catch ( \Exception ) {} }}
{{if $css !== NULL}}
	{{\IPS\Output::i()->cssFiles[] = $css;}}

If you want to load them by filename and group you'd have to either query for it, or hook into \IPS\cms\Templates and create your own helper method. load() will only accept template_id or template_key, but template_key also contains the id.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...