|
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 |
kaitlyn2004 Smarty Regular
Joined: 26 Apr 2007 Posts: 47
|
Posted: Thu Feb 17, 2011 4:32 pm Post subject: Cannot assign variable with hyphen in key? |
|
|
It appears this does not work:
{$myvar.my-key.my-sub-key="Test"}
Howver,
Code: | $myvar = array(
'my-key' => array(
'my-sub-key' => 'Test'
)
); |
is valid...
Bug? Workaround? |
|
Back to top |
|
kaitlyn2004 Smarty Regular
Joined: 26 Apr 2007 Posts: 47
|
Posted: Thu Feb 17, 2011 4:40 pm Post subject: |
|
|
Saw a couple of discussions saying don't use hyphens in keys..
Problem is I want to do something like:
{$meta.http-equiv.content-type="Test..."}
so that in my header it becomes <meta http-equiv="content-type" content="Test..." />
I could use underscores converted to hyphens... extra overhead... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 17, 2011 4:40 pm Post subject: |
|
|
I do believe that dash "-" is not a valid Smarty variable name, and that includes array keys. PHP highly discourages them because they appear as subtraction, and you have to enclose things in braces and quotes to make them work. Bottom line, avoid using dashes in array keys and values, in both PHP and Smarty. Use underscore instead. |
|
Back to top |
|
kaitlyn2004 Smarty Regular
Joined: 26 Apr 2007 Posts: 47
|
Posted: Thu Feb 17, 2011 4:40 pm Post subject: |
|
|
mohrt wrote: | I do believe that dash "-" is not a valid Smarty variable name, and that includes array keys. PHP highly discourages them because they appear as subtraction, and you have to enclose things in braces and quotes to make them work. Bottom line, avoid using dashes in array keys and values, in both PHP and Smarty. Use underscore instead. |
Looks like I had just replied as you did... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 17, 2011 4:45 pm Post subject: |
|
|
You might be able to wrap them in a var (untested):
{$meta = "http-meta"}
{$type = "content-type"}
{$foo.$meta.$type = "foobar"}
But again, you may run into more hoop jumping later. Better off avoiding dashes altogether. |
|
Back to top |
|
kaitlyn2004 Smarty Regular
Joined: 26 Apr 2007 Posts: 47
|
Posted: Thu Feb 17, 2011 4:51 pm Post subject: |
|
|
Hmm.. this works!
{$meta.{"http-equiv"}.{"content-type"}="Testing!"} |
|
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
|