Page 1 of 1

custom tags help

Posted: Tue Jun 14, 2005 12:23 pm
by Silverviper
Hi,

I just installed CMSMS, an I was wondering how to pass arguments to my functions.
I've never used a CMS before so I'm unfamiliar with tags like  {myfunction}

I know I could pass the vars to the function within the custom tag, but I want my code to be reuseable.

dummy tag {myfunction}:

myfunction($var1,$var2,$var3){
//do your magic
}

thx

CD

Re: custom tags help

Posted: Tue Jun 14, 2005 2:31 pm
by Ted
If you do: {myfunction name="value"}, you can get that from your plugin with $params['name'];

Is that what you mean?

Re: custom tags help

Posted: Tue Jun 14, 2005 3:52 pm
by Silverviper
Hi

i want to call my function inside the {myfunction} tag

with plain php i would do like this:



and in my template



hope this helps to answer my question

thx

Chris

Re: custom tags help

Posted: Tue Jun 14, 2005 5:02 pm
by nils73
Try this in your user defined tag:

$var1 = "Hello World";
$smarty->assign('var1', $var1);

and in the template or page use:

{$var1}

to output the value ...

Regards,
Nils

Re: custom tags help

Posted: Wed Jun 15, 2005 7:30 am
by Silverviper
Hi,

ok lets give it one more try,

here's my real function, it may give you a better understanding of my problem

Code: Select all

<?
function asciime($tag, $user, $at, $domain){

 $myarray = array($tag,$user,$at,$domain);
 $a=0; 
 foreach ($myarray as $new) {
     $i=0; 
 	 do {
        $codechar =  substr($new,$i,1); 
        $code = ord($codechar);
        	if($code == "&#0"){ 
				print ""; 
			} else { 
        	$myval[$a] = $myval[$a]."&#$code;";  
			}
   		$i++;
        } 
        while($codechar != ""); 
   $a++;
 } 
	   
print '<__script__ language="JavaScript">
var domain = "'.$myval[3].'";
var user = "'.$myval[1].'";
var recipient = user + "'.$myval[2].'" + domain
var makeurl = "'.$myval[0].'" + recipient
document.write(recipient.link(makeurl))
</__script>';
}
?>
function usage in a non CMSMS page

Code: Select all

<?
include 'antiharvester.php';
asciime("mailto:","yourname","@","yourdomain.com");
?>
what i have done so far is to put the asciime function in my custom
tags and named it {antiharvester} without the tags of course.

I have tried what you guys suggested but no luck.

put this in my template {antiharvester tag="mailto:" user="yourname" at="@" domain="yourdomain"}

and put this within the asciime function in my custom tag {antiharvester}

Code: Select all

$tag = $params['tag'];
$user = $params['user'];
$at = $params['at'];
$domain = $params['domain'];
thx

Chris

Re: custom tags help

Posted: Wed Jun 15, 2005 9:41 am
by Ted
So the code for your user defined tag is:

Code: Select all

$tag = $params['tag'];
$user = $params['user'];
$at = $params['at'];
$domain = $params['domain'];

$myarray = array($tag,$user,$at,$domain);
$a=0; 
foreach ($myarray as $new) {
     $i=0; 
    do {
        $codechar =  substr($new,$i,1); 
        $code = ord($codechar);
             if($code == "&#0"){ 
                             print ""; 
                      } else { 
         $myval[$a] = $myval[$a]."&#$code;";  
                     }
                  $i++;
        } 
        while($codechar != ""); 
   $a++;
} 
    
print '<__script__ language="JavaScript">
var domain = "'.$myval[3].'";
var user = "'.$myval[1].'";
var recipient = user + "'.$myval[2].'" + domain
var makeurl = "'.$myval[0].'" + recipient
document.write(recipient.link(makeurl))
</__script>';
?

Remeber that a user defined tag is actually a function itself, so putting a function inside a function isn't going to work.

Re: custom tags help

Posted: Wed Jun 15, 2005 9:56 am
by Silverviper
Hi,

Thx for clarifying that the tag is a function in itself.

I removed function asciime($tag, $user, $at, $domain) and now it works as it should

Thx to all of you for your support

Chris

Re: custom tags help

Posted: Wed Jun 15, 2005 11:25 am
by nils73
If you are trying to create a function for hiding e-mail addresses from spambots, you can also use this one:

{mailto address=$EmailAddress encode="javascript" subject="Hello"}

You will find more useful infos here (the manual):

http://smarty.php.net/manual/en/

or simply read it in the wiki:

http://wiki.cmsmadesimple.org/tiki-inde ... ilto+Links

Regards,
Nils

Re: custom tags help

Posted: Thu Jun 16, 2005 7:41 am
by Silverviper
Thanks for the tip Nils

Chris