|
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 |
Ragnarok Smarty n00b
Joined: 19 Mar 2009 Posts: 2
|
Posted: Sun Mar 22, 2009 10:44 am Post subject: How to write assign plugin? |
|
|
Hi guys!
I just started to learn about smarty and i have a question.
I need implement a system where designer can write in template something like this:
<a href="$BASE_URL">Home</a>
Hello dear user!
You are watching article {$MyTag-ArticleTitle} on the {$FULL_URL} posted by {$MyTag-Author}
And user could see the title of current article on the page. So i need to assign the $ArticleTitle variable.
How can i do it? I mean i need to write a plugin that will check all the varibles in the template and if the first word of variable is "MyTag", value provided by me should be assigned to this variable. I can't just do it from controller, because there can a lot of tpl's or controllers, so i need the one place for code.
And the second this function should know current url to i can get currentarticle by url www.cms.local/articles.php?article="hello_world"
Thank you! |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Mon Mar 23, 2009 12:58 pm Post subject: |
|
|
sounds like you are making this way too complicated.
I don't quite understand what you are trying to do, but maybe you could just have a separate variable called mytag? If that's not the solution, you really need to rethink how you are doing this. |
|
Back to top |
|
Ragnarok Smarty n00b
Joined: 19 Mar 2009 Posts: 2
|
Posted: Tue Mar 24, 2009 12:38 pm Post subject: Done! Thanks! |
|
|
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.tag.php
* Type: function
* Name: tag
* Purpose: assign a value to a template variable
* -------------------------------------------------------------
*/
function smarty_function_tag($tag, &$smarty)
{
$url = $_SERVER['REQUEST_URI'];
$res = "123";
if (is_array($res)) $smarty->assign("t", $res);
else return $res;
}
?>
and then in template
{tag t="ex-categoryAlias-title"} |
|
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
|