Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

custom block plugin- not getting any output btwn {x} {/x}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
pfdobbs
Smarty n00b


Joined: 20 Aug 2003
Posts: 3

PostPosted: Wed Aug 20, 2003 12:38 am    Post subject: custom block plugin- not getting any output btwn {x} {/x} Reply with quote

I made a custom block function (smarty_block_ftform) and it works fine.
The function returns a string and that string is output to the page.

My close block {/ftform} also works, it puts output to the page in the same
manner.

My problem is getting output to the page in between these tags. Is it
intended behaviour that output is possible between the open and close
tag of a custom block plugin ?

If i do this for example in the template:
{ftform x="1" }
smarty rocks
{/ftform}

I do get the output from the open {ftform} and the close {/ftform} from
my block function code, but the page never has the words 'smarty rocks'.
Back to top
View user's profile Send private message
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Aug 20, 2003 8:40 am    Post subject: Reply with quote

Then you have done something wrong in your custom block function. Please post the code or look at http://smarty.php.net/manual/en/plugins.block.functions.php

This should be your function header:
Code:
function smarty_block_ftform($params, $content, &$smarty)


The second parameter ($content) contains the text between the opening and closing tags ({ftform}...{/ftform}).
Back to top
View user's profile Send private message
pfdobbs
Smarty n00b


Joined: 20 Aug 2003
Posts: 3

PostPosted: Wed Aug 20, 2003 1:05 pm    Post subject: looks right to me: Reply with quote

TESTBLOCK.PHP:

Quote:
<?php
require('Smarty_Test.php');
$smarty = new Smarty_Test;
$smarty->display('testBlock.tpl');
?>


TESTBLOCK.TPL:
Quote:

{ftform width="10" action = "/testBlock.php" }
smarty rocks
{/ftform}


BLOCK.FTFORM.PHP:
Quote:
<?php

function smarty_block_ftform( $params, $content, &$smarty)
{
echo "FORM BLOCK OUTPUT <br>";
}
?>


and for completeness, SMARTY_TEST.php
Quote:
<?php

require('Smarty.class.php');

class Smarty_Test extends Smarty {

function Smarty_Test() {
$this->Smarty();
$this->debugging = TRUE;
$this->template_dir = '\data\work\myhome\wk';
$this->compile_dir = '\data\work\myphp\smarty\wk\templates_c/';
$this->config_dir = '\data\work\myphp\smarty\wk\configs/';
$this->cache_dir = '\data\work\myphp\smarty\wk\cache/';
$this->clear_all_cache();
$this->caching = false;
$smarty->compile_check = true;
$this->assign('app_name','Guest Book');
}
}
?>



The output I get in my browser is :
Quote:

FORM BLOCK OUTPUT <br>FORM BLOCK OUTPUT <br>

but I don't see the words 'smarty rocks' as in the template.


I'm on a windows 2000 using smarty 2.5.0 and php 4.3.2
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Aug 20, 2003 1:11 pm    Post subject: Reply with quote

- first: you should return the output of your block and not echo it. (echo may work but is deprecated)

- second: you will only see "smarty rocks" when you return sth. that contains $content.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Aug 20, 2003 1:18 pm    Post subject: Reply with quote

Quote:
- first: you should return the output of your block and not echo it. (echo may work but is deprecated)
- second: you will only see "smarty rocks" when you return sth. that contains $content.


Therefore your block should like like this:
Code:
function smarty_block_ftform( $params, $content, &$smarty)
{
if ($content == null) {
  // Opening tag {ftform}
  echo "BEGIN OF FORM BLOCK OUTPUT <br>";
}
else {
  // Closing tag {/ftform}
  echo $content;
  echo "END OF FORM BLOCK OUTPUT <br>";
}
}


Then your output will look like this:
Code:

BEGIN OF FORM BLOCK OUTPUT <br>smarty rocksEND OF FORM BLOCK OUTPUT <br>
Back to top
View user's profile Send private message
pfdobbs
Smarty n00b


Joined: 20 Aug 2003
Posts: 3

PostPosted: Thu Aug 21, 2003 8:19 pm    Post subject: Reply with quote

Thanks everyone , its working as below with your help.

Code:
function smarty_block_ftform( $params, $content, &$smarty)
{
if ($content == null) {
     $output = sprintf(' <form name="form1" method="post" action="%s">
                   <table width="%d" border="0" cellspacing="0" cellpadding="6">',     
           $params['formAction'], $params['width']);
   echo $output;
}else{
     
   $output = $content.'</table></form>';
   echo $output;
}
}


However, I must point out that if substitute a 'return' instead of the echo on both calls, it does not give any ouput
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Aug 21, 2003 11:20 pm    Post subject: Reply with quote

[php:1:b2d5d327c4]<?php

function smarty_block_ftform( $params, $content, &$smarty)
{
if ($content !== null) {

$output = sprintf(' <form name="form1" method="post" action="%s">
<table width="%d" border="0" cellspacing="0" cellpadding="6">%s</table>
</form>',
$params['formAction'], $params['width'], $content);
return $output;
}
}

?>[/php:1:b2d5d327c4]

via return you cannot output sth. at the opening tag only at the closing one.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP