|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Tue Aug 31, 2004 11:37 am Post subject: Writing a Plugin |
|
|
Hi all,
how to use other plugins within my own written plugin?
I wann use the html_image plugin.
Greetz, kills |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Tue Aug 31, 2004 12:01 pm Post subject: |
|
|
I tried, but where is the mistake?
[php:1:79a6146246]
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty strip modifier plugin
*
* Type: modifier<br>
* Name: make_error<br>
* Purpose: Transform a String to an error Message
*
* Example: {$var|make_error}
* Date: August 31th, 2004
*
* @author Markus STaab
* @version 1.0
* @param string
* @return string
* @uses smarty_function_html_image()
*/
function smarty_modifier_make_error( $text, $append_break = true, $error_image = "images/layout/error.gif") {
require_once $this->_get_plugin_filepath('function', 'html_image'); // LINE 27
// require_once $smarty->_get_plugin_filepath('function', 'html_image'); wont work, too!
$text = smarty_function_html_image( array( "file" => $error_image, "alt" => $text), $this /*$smarty wont work, too*/) ."<p style=\"color: #FF0000;\">". $text ."</p>";
if ( $append_break) {
$text .= "<br />";
}
return $text;
}
/* vim: set expandtab: */
?>
[/php:1:79a6146246]
Code: |
Fatal error: Call to a member function on a non-object in D:\Development\PHP\MyProjects\st-carstyling\bin\classes\Smarty-2.6.3\plugins\modifier.make_error.php on line 27
|
|
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Tue Aug 31, 2004 12:13 pm Post subject: |
|
|
i found the mistake:
[php:1:66da800913]
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty make_error modifier plugin
*
* Type: modifier<br>
* Name: make_error<br>
* Purpose: Transform a String to an error Message
*
* Example: {$var|make_error}
* Date: August 31th, 2004
*
* @author Markus STaab
* @version 1.0
* @param string
* @return string
* @uses smarty_function_html_image()
*/
function smarty_modifier_make_error( $text, $append_break = true, $error_image = "images/layout/error.gif") {
global $oTpl;
require_once $oTpl->_get_plugin_filepath('function', 'html_image');
$text = smarty_function_html_image( array( "file" => $error_image, "alt" => $text), $oTpl) ."<p style=\"color: #FF0000;\">". $text ."</p>";
if ( $append_break) {
$text .= "<br />";
}
return $text;
}
/* vim: set expandtab: */
?>
[/php:1:66da800913]
i have to call the $oTpl var because of i had no standard configuration with the template var called "smarty".
Is there a general way to reference to the smarty object?
-----------------
why does the plugin not work correctly?
TPL:
[php:1:66da800913]
<tr>
<td>
Titel
</td>
<td>
{ validate field="title" criteria="notEmpty" message="Der Titel des Artikels fehlt!"|make_error }
<input type="text" style="width:100%" class="text" name="title" value="{ $title }" maxlength="255"/>
</td>
</tr>
<tr>
<td>
Einleitung
</td>
<td>
{ validate field="intro" criteria="notEmpty" message="Die Einführung des Artikels fehlt!"|make_error }
<textarea style="width:100%" class="text" name="intro">{ $intro }</textarea>
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="2">
<input type="submit" value="Speichern" />
</td>
</tr>
[/php:1:66da800913]
Output:
[php:1:66da800913]
<tr>
<td>
Titel
</td>
<td>
Der Titel des Artikels fehlt!
<input type="text" style="width:100%" class="text" name="title" value="" maxlength="255"/>
</td>
</tr>
<tr>
<td>
Einleitung
</td>
<td>
Die Einführung des Artikels fehlt!
<textarea style="width:100%" class="text" name="intro"></textarea>
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="2">
<input type="submit" value="Speichern" />
</td>
</tr>
[/php:1:66da800913]
where are my images? |
|
Back to top |
|
|
|
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
|