Gossamer Forum
Home : Products : Gossamer Links : Discussions :

loop problems

Quote Reply
loop problems
I've finally taken the plunge and upgraded to GLinks - and now I'm trying to mend all the bits I've broken!

This one I'm really stuck on.
I have a loop that looks like this in the tag dump:

LoopName
[
{
'field1' => 'value1',
'field2' => 'value2'
},
{
'field1' => 'value1',
'field2' => 'value2'
}
]

But when I loop over LoopName in the template all the fields have value 0. It was working before I upgraded as far as I am aware. Any ideas anyone?

Thanks,
Laura.
The UK High Street
Quote Reply
Re: [afinlr] loop problems In reply to
Having spent a huge amount of time on this I seem to have finally got to the answer that tag names cannot include a hyphen.

Any suggestions for a way around this?
Quote Reply
Re: [afinlr] loop problems In reply to
Hi,

Mmm.. did they support hyphens in previous versions? Can't say I ever tried it... but I would have thought it would cause problems anyway.

i.e you can't use;

if $var-name , but would have to use $var_name (i.e an underscore instead), as I don't think Perl allows hyphens in variable names?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] loop problems In reply to
Yes, definitely did support hyphens in previous versions. It seems that the template parser now does algebra on plain tags rather than just 'set' operations which is what is causing me the problem. So for example

<%a-b%>

rather than returning the tag 'a-b' tries to do the subtraction a-b and always results in 0 if the tags a and b do not exist. I think it would be better to get an 'Unknown tag: a' error as this would at least give an indication of what the problem is.

This is really causing me problems as I am using xml files supplied by another company which have hyphens in the variable names which I have been using in the templates. I suppose I'm going to have to rename all the keys of the hashes (very annoying) as I can't think of any other way around it - apart from modifying the parser ...
Quote Reply
Re: [afinlr] loop problems In reply to
Solution: replace '-' with '_' in xml before it is converted to perl objects. Does this seem sensible? And is this the best regex?

$xml=~s/(<\/?[^>]*)\-([^>]*>)/$1$2/g;

Edit: this will only match the first hyphen in the tag name - how can I match all of them?

Last edited by:

afinlr: Jan 15, 2006, 6:53 AM