Parveen Kumar
Parveen Kumar

Reputation: 59

Simple hello word plugin in MODx Revolution

I am new to MODx Revolution. I want to create simple hello word plugin in MODx.

Please help! Thanks

Upvotes: 1

Views: 159

Answers (1)

sepiariver
sepiariver

Reputation: 521

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".

Right-Click to add New Plugin

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

Hello World MODX Plugin

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.

enter image description here

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.

Upvotes: 2

Related Questions