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

need help with function

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
marshell
Smarty n00b


Joined: 22 Oct 2012
Posts: 4

PostPosted: Mon Oct 22, 2012 10:18 am    Post subject: need help with function Reply with quote

(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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Oct 23, 2012 6:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
marshell
Smarty n00b


Joined: 22 Oct 2012
Posts: 4

PostPosted: Tue Oct 23, 2012 10:26 pm    Post subject: Reply with quote

got it working now, thanks!
Back to top
View user's profile Send private message
marshell
Smarty n00b


Joined: 22 Oct 2012
Posts: 4

PostPosted: Wed Oct 24, 2012 7:20 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Oct 29, 2012 1:40 pm    Post subject: Reply with quote

$foo = $smarty->getTemplateVars('product');

Now you can access it in PHP as array $foo['title']
Back to top
View user's profile Send private message
kingnalz
Smarty Rookie


Joined: 21 Aug 2013
Posts: 11

PostPosted: Mon Aug 26, 2013 3:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
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 -> Plugins 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