问题描述:

I am new to MODx Revolution.

I want to create simple hello word plugin in MODx.

Please help!

Thanks

网友答案:

From the "Elements" tab of the Tree view (left-hand side of the MODX Manager) right-click on the top-level "Plugins" item, and select "New Plugin".

In the Plugin Edit View, give your Plugin a name, and then add your PHP code.

As you can see, printing directly from the Plugin will not result in anything being rendered on a page request. You must enable the System Event on which you want your Plugin to fire, depending on what you're trying to accomplish. You can do this in the "System Events" tab of the Plugin Edit View.

In the above example, I've enabled the Plugin 'OnWebPageInit', which allows me to call the MODX method setPlaceholder() which will set the value of a MODX Placeholder tag within the Template(s) used for rendering a web page. (see code comments in the screenshot above)

For reference, some of the most often-used MODX methods are described in detail here.

Depending on what you're trying to do, a Plugin may not actually be the best place for your code. You might want to instead write a Snippet, which you can call into your Template(s) where and when you need it to execute.

Both Plugins and Snippets allow you to expose certain variables to be set at runtime. Such variables are available in your Snippet or Plugin code as elements in the $scriptProperties array.

相关阅读:
Top