Page 1 of 1

Help programming User Defined Tag to call Smarty Function {mailto}

Posted: Tue Dec 05, 2006 4:52 am
by websherpa
I am not a proficient PHP coder (in fact less than a hack), but I need help to accomplish this:

Within a template I have set a hidden content block to capture an email address in the Page Editor, then pass it to the {mailto} Smarty, thus:

Code: Select all


<div id="hidden">{content block="email" oneline='true' wysiwyg='false' assign=email1}</div>
{mailto address=$email1 encode='hex'}

All well and good except that if the "email" block is empty, then I get an error, so I am wondering how to correctly code either the template or call some script in a User Defined Tag to only call the Smarty {mailto} if the $email1 isn't empty? 

I thought of doing something this:

Code: Select all


if ( isset($params['email1']) && !empty($params['email1'])) { 

then execute a {mailto ...};
}

But I don't know my PHP or smarty well enough to know how to form the {mailto} call within a PHP script - if it can be done.

Any help on this?  Thank you.  I am learning gobs but this one I have hit the wall of my own grasp of PHP syntax.

Wayne

Re: Help programming User Defined Tag to call Smarty Function {mailto}

Posted: Tue Dec 05, 2006 5:11 am
by cyberman
I'm not a coder for real too but I suggest you should use Smarty pure :)

Code: Select all

{if $email1 neq ''}
   {mailto ...}
{/if}

Re: Help programming User Defined Tag to call Smarty Function {mailto}

Posted: Tue Dec 05, 2006 5:22 am
by websherpa
Well there you go, I knew it would be something simple.  Thank you!

I am curious still, however, whether you can call or set up a smarty function with a parameter from within PHP and and example of just how you would code it.

Re: Help programming User Defined Tag to call Smarty Function {mailto}

Posted: Tue Dec 05, 2006 5:38 am
by cyberman
You have to enable "Use smarty php tags" in config.php. Then you can use too in template

Code: Select all

{php}
if ( isset($params['email1']) && !empty($params['email1'])) {
{/php}

   {mailto ...}

{php}
}
{/php}