View previous topic :: View next topic |
Author |
Message |
pfdobbs Smarty n00b
Joined: 20 Aug 2003 Posts: 3
|
Posted: Wed Aug 20, 2003 12:38 am Post subject: custom block plugin- not getting any output btwn {x} {/x} |
|
|
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 |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Wed Aug 20, 2003 8:40 am Post subject: |
|
|
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 |
|
pfdobbs Smarty n00b
Joined: 20 Aug 2003 Posts: 3
|
Posted: Wed Aug 20, 2003 1:05 pm Post subject: looks right to me: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Aug 20, 2003 1:11 pm Post subject: |
|
|
- 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 |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Wed Aug 20, 2003 1:18 pm Post subject: |
|
|
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 |
|
pfdobbs Smarty n00b
Joined: 20 Aug 2003 Posts: 3
|
Posted: Thu Aug 21, 2003 8:19 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Aug 21, 2003 11:20 pm Post subject: |
|
|
[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 |
|
|