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.

Widgets /

Discuss SilverStripe Widgets.

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

Problems creating a simple widget


Go to End


1777 Views

Avatar
nw

Community Member, 3 Posts

6 October 2012 at 1:14am

Edited: 06/10/2012 2:44pm

[Update] I think I've got it working now. It seems that having:

class MyWidget_Controller extends Widget_Controller { 
	function WidgetHolder() { 
			return $this->renderWith("WidgetHolder"); 
	}
}

in the widgets PHP code makes everything work. I'm still not sure if that's the right way to do things, but it works.
---------

Hi, I'm trying to make a fairly simple widget, but having some trouble. The main thing I want to achieve is for a piece of html to be outputted (so that an iframe is displayed within the widget area), with this snippet containing a username entered by the site admin.
i.e. something like <iframe src="example.com/username/pages"></iframe> should be the outputted source of the widget, with the username portion having been entered in the widget tab by an admin.

However, I'm having some trouble (I'm fairly new to Silverstripe and PHP): I managed to get the basic widget structure running fine, but I'm stuck on how to output the html snippet from the widget's php file to its ss file. Looking at similar (but older) widgets, it seems like this would be done something like:

	function iframeOut() {
		$output = '<iframe src="http://www.example.com/' . $UserName . '/pages"></iframe>';
	return $output;
	}

and then in the widget ss file, simply have $iframeOut to include the iframe HTML snippet. The problem is, this isn't working for me (absolutely nothing is included in place of the $iframeOut in the .ss file). Any suggestions as to what I'm doing wrong would be greatly appreciated!