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

Calling the {include} function from a function-plugin?

 
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
Alphanimal
Smarty Rookie


Joined: 24 Apr 2004
Posts: 15

PostPosted: Wed Jul 26, 2006 9:25 pm    Post subject: Calling the {include} function from a function-plugin? Reply with quote

Hi!
I want to make a built-in template editor for my page.
so every template that is displayed should get a header with a "edit" link when in edit-mode.
i have a main template that has the HTML-head and the main layout, and {include}s for the menu and the main content ...

I thought of not using the {include} function but an other (plugin) function {content} that automatically adds the header with the "edit" link.

so this function-plugin should check if edit-mode is active (assigned bool variable "edit_mode_active"?) and then either display a template that has the header and uses {include} to actually display the template or just displays it without header.

so i thought of something like this:
instead of {include} i use my own {content}:
Code:
function smarty_function_content($params, &$smarty){
   if($smarty->get_template_vars("edit_mode_active")){
      execute "{include file=$params["file"]}"; //???
   }else{
      execute "{include file='edit_header.tpl' content=$params["file"]}"; //???
   }
}

the edit_header.tpl could contain something like this:
Code:
<p><a href="edit_template.php?file={$content}">Edit</a></p>
{include file=$content}
just adding a link to the template (also could show a border or something)

this {content} function should now be used instad of {include} to automatically add headers if needed.

i used "execute" as pseudocode in the function.
is there a better way to execute smarty functions like they were in the template but from PHP in a function plugin?
Or is there at least a eval-function to execute smarty code?

thanks in advance!
greets from lower austria!
Daniel[/code]
Back to top
View user's profile Send private message MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jul 27, 2006 7:11 am    Post subject: Reply with quote

Sure.... but it is always best to return the content from a function -- so to emulate the include functionality of the template, just use the API fetch function: http://smarty.php.net/manual/en/api.fetch.php and return the result (also, you can assign any template variables that are required before you do the fetch).

Another idea is to implement a custom resource that does the checks for you -- that way you can still use normal {include} calls. Its all in the manual -- but feel free to ask if you need more help Wink
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 -> 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