custom tags help

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
Silverviper

custom tags help

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: custom tags help

Post by Ted »

If you do: {myfunction name="value"}, you can get that from your plugin with $params['name'];

Is that what you mean?
Silverviper

Re: custom tags help

Post 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
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: custom tags help

Post 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
Silverviper

Re: custom tags help

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: custom tags help

Post 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.
Silverviper

Re: custom tags help

Post 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
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: custom tags help

Post 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
Silverviper

Re: custom tags help

Post by Silverviper »

Thanks for the tip Nils

Chris
Locked

Return to “CMSMS Core”