|
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 |
marshell Smarty n00b
Joined: 22 Oct 2012 Posts: 4
|
Posted: Mon Oct 22, 2012 10:18 am Post subject: need help with function |
|
|
(complete smarty noob)
Trying to write this function but am getting nowhere, here's what I have so far...
Code: | <?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.comments.php
* Type: function
* Name: comments
* Purpose: outputs a comments/review form
* -------------------------------------------------------------
*/
function smarty_function_comments($params, &$smarty)
{
// Start the output buffer
ob_start();
// Commentics configuration
$cmtx_page_id = "pageid";
$cmtx_reference = "Page title";
$cmtx_path = "./././comments/";
define ('IN_COMMENTICS', 'true');
// Call commentics
require $cmtx_path . "includes/commentics.php";
// Grab code from the output buffer
$comments = ob_get_clean();
// Assign code to a template variable
$smarty->assign("comments",$comments);
}
?> |
and in the template file:
{$comments}
just not getting any output at all. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Oct 23, 2012 6:24 pm Post subject: |
|
|
You accessed the variable $comments, but did never call the plugin.
Code: | {comments} <- call the plugin
{$comments} <- access the variable |
You will not need the variable and just call the plugin if you return the result in the plugin
Code: | function smarty_function_comments($params, &$smarty)
{
// Start the output buffer
ob_start();
......
// Return code from the output buffer
return ob_get_clean();
} |
|
|
Back to top |
|
marshell Smarty n00b
Joined: 22 Oct 2012 Posts: 4
|
Posted: Tue Oct 23, 2012 10:26 pm Post subject: |
|
|
got it working now, thanks! |
|
Back to top |
|
marshell Smarty n00b
Joined: 22 Oct 2012 Posts: 4
|
Posted: Wed Oct 24, 2012 7:20 am Post subject: |
|
|
Just have one issue now, I want to use each product name for the page ID, the product name is outputted using $product.title in the template, how can i use this inside the function? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Oct 29, 2012 1:40 pm Post subject: |
|
|
$foo = $smarty->getTemplateVars('product');
Now you can access it in PHP as array $foo['title'] |
|
Back to top |
|
kingnalz Smarty Rookie
Joined: 21 Aug 2013 Posts: 11
|
Posted: Mon Aug 26, 2013 3:15 pm Post subject: |
|
|
Hello,
Can somebody teach me to using this code and plugin?
I cannot get.
please teach me how to write at php files and tpl files.
urgent,
thank you. |
|
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
|