Jump to content
View in the app

A better way to browse. Learn more.

Learn more

Output template for Widget that is not uses "\IPS\Widget" instead of "\IPS\Widget\StaticCache"

Featured Replies

I’m developing a custom widget for my application and I’m using the base class \IPS\Widget (not StaticCache or PermissionCache). The widget renders correctly when I return a string directly, but fails when I try to use a template via $this->output().

The widget and template is a basic html input for that takes user input via math.js JavaScript library. It calculates the input and output it. There's no dynamic PHP or AJAX calls.

The IPS documentation says that when using \IPS\Widget, the template should not be assigned using the standard format: $this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );

public function init() : void
	{
		// Use this to perform any set up and to assign a template that is not in the following format:
		// $this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );
		// Note: parent::init() will set a default template if you haven't, so make sure your template is defined BEFORE the parent is called.

		parent::init();
	}

Then the template is supposed to be render via:

public function render(): string
	{
		// Use $this->output( $foo, $bar ); to return a string generated by the template set in init() or manually added via $widget->template( $callback );
		// Note you MUST route output through $this->output() rather than calling \IPS\Theme::i()->getTemplate() because of the way widgets are cached
		
		return $this->output();
	}

5 hours ago, EDK-Tech said:

The IPS documentation says that when using \IPS\Widget, the template should not be assigned using the standard format: $this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );

Where are you reading this?

  • Author

In /applications/{my-app}/widgets/{widget}.php . Using the Developer Center, I generated an \IPS\Widget class. The version that I'm developing on is 5.0.13 or 5.0.15.

  • Author

Looks like the SIMPLY solution is to name the template the same as the widget key.

Recently Browsing 0

  • No registered users viewing this page.

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.