Basic Widget ============ Create a widget that will display “Hello, World!” and optionally any text the user wants. In Elgg, widgets are those components that you can drag onto your profile or admin dashboard. This tutorial assumes you are familiar with basic Elgg concepts such as: * :doc:`/guides/views` * :doc:`/admin/plugins` You should review those if you get confused along the way. .. contents:: Contents :local: :depth: 1 Adding the widget view code --------------------------- Elgg automatically scans particular directories under plugins looking for particular files. :doc:`/guides/views` make it easy to add your display code or do other things like override default Elgg behavior. For now, we will just be adding the view code for your widget. Create a file at ``/views/default/widgets/helloworld/content.php``. “helloworld” will be the name of your widget within the hello plugin. In this file add the code: .. code-block:: php [ 'helloworld' => [ 'name' => 'Hello, world!', 'description' => 'The "Hello, world!" widget', ], ], ]; Now go to your profile page using a web browser and add the “hello, world” widget. It should display “Hello, world!”. .. note:: For real widgets, it is always a good idea to support :doc:`/guides/i18n`. Allow user customization ------------------------ Click on the edit link on the toolbar of the widget that you've created. You will notice that the only control it gives you by default is over access (over who can see the widget). Suppose you want to allow the user to control what greeting is displayed in the widget. Just as Elgg automatically loads ``content.php`` when viewing a widget, it loads ``edit.php`` when a user attempts to edit a widget. Put the following code into ``/views/default/widgets/helloworld/edit.php``: .. code-block:: php