View previous topic :: View next topic |
Author |
Message |
ericingram Smarty Rookie
Joined: 16 Nov 2011 Posts: 21
|
Posted: Sat Nov 19, 2011 5:22 pm Post subject: How to add a new internal tag? |
|
|
First, let me say I am very excited about Smarty 3. Huge syntax improvement.
That said, I want to create a new tag (internal or external doesn't matter), that looks like this:
{get "some/string" => $result}
I tried accomplishing this by copying the smarty_internal_compile_foreach class, but then realized the rules for expected tokens are built into the parser. I'm totally willing to hack the internal code to make this work, because it's important to my project.
Any help?
Thank you very much! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Nov 19, 2011 5:51 pm Post subject: |
|
|
See http://www.smarty.net/docs/en/plugins.functions.tpl for implementing plugins. However this follows the standard Smarty syntax how attributes are defined.
Do you really need a syntax exact like this:
{get "some/string" => $result}
This would indeed mean to hack the lexer and parser. |
|
Back to top |
|
ericingram Smarty Rookie
Joined: 16 Nov 2011 Posts: 21
|
Posted: Sat Nov 19, 2011 6:20 pm Post subject: |
|
|
Thanks for the reply -- really appreciate the support here!
I would *really* like to achieve that syntax. It would be great if it were possible to accomplish custom syntax with custom plugins, but I am willing to hack the lexer and parser if I can figure it out.
However, I suppose the next best option would look like:
{get "some/string" $result}
Which I think we can easily accomplish with shorthand attributes. That brings up another question, is it possible to use shorthand attributes with plain-old custom plugins? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Nov 19, 2011 8:04 pm Post subject: |
|
|
The Lexer/Parser is generated by tools which are not part of the normal Smarty distribution.
Messing around with the Smarty syntax can have a lot of side effects. Also upgrading to newer Smarty versions could become an issue.
So I really can't recommend to look into a solution like this.
You can implement shorthand attributes by using compiler plugins.
See http://www.smarty.net/docs/en/plugins.compiler.functions.tpl
I just found out that the documentation is a bit incorrect.
The first parameter is not a string but an array of precompiled attribute values. |
|
Back to top |
|
ericingram Smarty Rookie
Joined: 16 Nov 2011 Posts: 21
|
Posted: Sun Nov 20, 2011 4:11 pm Post subject: |
|
|
Ahh that makes sense, thanks for the help! |
|
Back to top |
|
ericingram Smarty Rookie
Joined: 16 Nov 2011 Posts: 21
|
Posted: Sun Nov 20, 2011 7:12 pm Post subject: |
|
|
I came across another problem trying to implement this tag:
{post $data to "/uri"}
For some reason "to" is a reserved word? I can use "in" and get no error, but "to" gives me:
Unexpected " to ", expected one of: "}" , " "
Any way around this? Thanks! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Nov 20, 2011 9:40 pm Post subject: |
|
|
yep, to is a reserved keyword in Smarty syntax as it is used in the {for} tag.
No way to get around it. |
|
Back to top |
|
ericingram Smarty Rookie
Joined: 16 Nov 2011 Posts: 21
|
Posted: Wed Nov 30, 2011 3:21 pm Post subject: |
|
|
Is there any built-in way to create a pre-compiler that would let me get around these compiler rules? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
|