Article: Admin Panel > Extensions > User Defined Tags

Submit and proof-read articles for the documentation here. Anyone is welcome to contribute!
Locked
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Article: Admin Panel > Extensions > User Defined Tags

Post by Elijah Lofgren »

Copied from here: http://72.14.203.104/search?q=cache:8w9 ... nt=firefox

Suggested place to post it: http://wiki.cmsmadesimple.org/en:adminp ... efinedtags

Title: Writing a Basic User Defined Tag

How to Make a User Defined Tag

Like most things in CMS, adding a new plug-in is simple, although it's not quite like a holiday.

To add your own plugin follow these steps...

  1. The plugin editor is in the back-end so you need to login as admin, or a user with appropriate permissions.
  2. In the admin panel click on 'Plugin Management' on the menu bar on the left.
  3. At the bottom of the page click 'Add User Defined Tag'.
  4. In the 'Name' text-box type the name of the tag. This is what you'll have to type in parenthesies to add a tag into a page so be descriptive but don't make it long.
  5. In the 'Code' text-box type the php code that the tag will be replaced with when the page is requested. (Check the next section for more info)
  6. Click on the 'Submit'.


Your First UDT

Instead of me rambling on about every last detail of plugins and php a simple example should help you get started. Following in the footsteps of all introductions to programming we'll try a hello world script first.

Follow the steps above to create a new plug-in, 'Name' it "helloworld" (no quotes) and in the 'Code' box type/paste this code...

echo "Hello World!";

Click 'Submit'. To test the module, create a new 'Content Page' (see [{{Handbook.ContentDetails}} this guide]]), type "{helloword}" (no quotes) somewhere in the body and then click 'Preview'. Instead of seeing {helloworld} you should see "Hello World!".

The echo command just writes what's in the quotes so we can also use this to add HTML, or even DHTML or Javascript objects. Try out this code, just edit the plugin we made by clicking on the edit icon next to it on the 'Plguin Managment' page. Try this code...

echo "Hello World!";

Test it in the same way as with the last one, you should now see something that looks a bit like this:


Hello World!


"But you can do all that with a html blob!" I hear you cry. Well, plugins get really useful when you start to add parameters. Parameters alow you to specify something in the tag. Let's say that we wanted to say hello to someone called Bob, try this code...

echo "Hello ".$params['name']."!";

This had added a parameter, "name", to the plugin, the contents of that parameter will be put there when the plugin is called from a tag in a page. Test it in the same way as before, but instead of using "{helloworld}" use "{helloworld name='Bob'}" as the tag to define the name parameter. You should see something like this...


Hello Bob!



That just about covers writing basic plugins, you can do some useful things with the echo command, parameters and a little imagination so just think what you can do if you learn a little PHP...


My addition:

You can access the page content in a user defined tag by passing it as a parameter:

In your template:
{content assign=pagecontent}
{table_of_contents thepagecontent="$pagecontent"}

In your user defined tag named "table_of_contents":
echo $params['thepagecontent']; // Display page content.

I use this so I can parse to the page content to automatically create a table of contents.
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
Locked

Return to “Suggestions, Modifications & Corrections”