• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Article: Admin Panel > Extensions > User Defined Tags
PostPosted: Mon Apr 24, 2006 6:03 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Mon Apr 24, 2006 1:01 am
Posts: 811
Location: Deatsville, AL
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. :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting