Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Help With Global

(Page 1 of 2)
> >
Quote Reply
Help With Global
I have a simple global in and working now. I just want to jazz it up a bit.

Essentially, my problem is with alternate titles. I list them (things like possible English translations, alternate titles, etc) in a seperate field called "Eng_Title". In my database, I list all the alternate titles seperated by a "space-comma-space" delimiter, and this works fine. I have the global subsitite the "space-comma-space" with formatting- basically I italisize the entry, and put quote marks around it. Works fine. Here is my code:

sub {
use strict;
my ($rec) = @_;

my $short = $rec->{'Eng_Title'};
my $id = $rec->{'ID'};
$short =~ s/ , /<\/i>\", \"<i>/g;
return $short;
}

So here is what I want to do to spice things up. I would like the final subsitution in the list (if there is a list, sometimes I might only have one alt title) to be a '</i>" and "<i>'- adding an "and" in there. Not sure how to ONLY substitutre the last instance.

And I would also like to return a second variable- I do not care, a 1 and 0, a yes or no, I do not care, but some sort of flag to my template that says whether there is one or more than one item in the list, so I can add a "s" to the banner. So in the template, it would be: Alternate Title<%if flag%>s<%endif%>. Make sense?

If you want to see this in action, here is the page I have dummied up for testing:

Test Page

Look under the "Cartoon Production Information" banner for the results...

Thank You!

dave

Big Cartoon DataBase
Big Comic Book DataBase

Last edited by:

carfac: May 14, 2008, 9:14 AM
Quote Reply
Re: [carfac] Help With Global In reply to
Hi,

Do you have an example of the data in Eng_Title? May help try and work out what your trying to do. Bit vague at the moment ;)

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] Help With Global In reply to
Hey Andy!

Hope all is well.

OK, for the page I linked to, the data is: "Legend of the White Serpent , Tale of the White Serpent , Panda and the Magic Serpent , The White Snake Enchantress"

(without the quotes)

With template formating, this displays as:

English Title: "Legend of the White Serpent", "Tale of the White Serpent", "Panda and the Magic Serpent", "The White Snake Enchantress"

I would like this to display as:

English Titles: "Legend of the White Serpent", "Tale of the White Serpent", "Panda and the Magic Serpent" and "The White Snake Enchantress"

The changes I want to make show as red

Current template code:

<%if Eng_Title%>
<h4><b>English Title</b>: "<i><%Eng_Title_1%></i>"</h4><br /><br />
<%endif%>

with Eng_Title_1 being the global I posted above.

dave

Big Cartoon DataBase
Big Comic Book DataBase

Last edited by:

carfac: May 14, 2008, 11:07 AM
Quote Reply
Re: [carfac] Help With Global In reply to
Hi,

Try this:

Code:
sub {

my @split = split /,/, $_[0];
my @return_loop;

my @tmp_vals;
my $i = 0 ;
foreach (@split) {
$i++;
if ($i == $#split) {
push @tmp_vals, { Value => $_, isLast => 1 };
} else {
push @tmp_vals, { Value => $_};
}

}

if ($tmp_vals[0]) {
my $num;
if ($#tmp_vals > 0) { $num = 1; }
return { outputted => \@tmp_vals, outputted_number => $num };
}
}

Call it whatever your global was called before.

Then, call with:

Code:
<%your_global_name($Eng_Title)%>
<%if outputted.length%>
<h2>English Title<%if outputted_number%>s<%endif%></h2>
<%loop outputted%>
<i><%Value%></i>
<%endloop%>

<%endif%>

Untested - but something like that should work :)

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!

Last edited by:

Andy: May 14, 2008, 12:07 PM
Quote Reply
Re: [carfac] Help With Global In reply to
OK, I know how to figure out if the "s" should be there- I am just not sure how to pass it.

I can do:

my $listlen_x = @list_x;
if ($listlen_x < 2) {
my $s = '0';
}
else {
my $s = '1';
)

and thgen in the template, if s=1, add the "s"... no problem. but how do I pass that? Do I, in the last line of the plug in, do this?

return $output, $s;

I guess my question on this part is how do I return TWO variables- the formatted list, and the variable to show an s or not...



dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Help With Global In reply to
OK, nevermind- thanks for your better way. I will give that a shot now!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [Andy] Help With Global In reply to
There is no need of special check in global about number of vars, you can just do:

Code:
<h2>English Title<%if outputted.length > 1%>s<%endif%></h2>

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Help With Global In reply to
Good point :P

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: [eupos] Help With Global In reply to
Thanks Eupos- not a command I had known!

Andy:

Not sure if I am referencing the output correctly. In the first position, I used:
<%Eng_Title_1($Eng_Title)%>

Where Eng_Title_1 is the global name, and $Eng_Title... seems to work there. But I am getting an Unknown Tag: 'Value'" error... id <%Value%> correct for the template???? Or was I supposed to put something else in there? (I tried outputted and split!)

dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Help With Global In reply to
Sorry, my mistake...change:

Code:
return { outputted => \@split, outputted_number => $num };

..to:


Code:
return { outputted => \@tmp_vals, outputted_number => $num };

Silly coding mess up Tongue

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: [carfac] Help With Global In reply to
I would do something like:
Code:
sub {
my $title = shift;
return $title ? [split(/\s+,\s+/, $title)] : [];
}
and then in the template:
Code:
<%~if Eng_Title%>
<%set Eng_Title_loop = title_split($Eng_Title)%>
English Title<%if Eng_Title_loop.length > 1%>s<%endif%>: <%loop Eng_Title_loop%><%if Eng_Title_loop.length > 1 and not first%><%if last%> and <%else%>, <%endif%><%endif%>"<%loop_value%>"<%endloop%>
<%~endif%>

Adrian

Last edited by:

brewt: May 14, 2008, 1:09 PM
Quote Reply
Re: [Andy] Help With Global In reply to
Bingo! That was it! Thank you.

Any EASY way to add an "and" for the last part of the list instead of all commas????
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Help With Global In reply to
Glad it worked.

Regarding your other question - try this revised version:

Code:
sub {

my @split = split /,/, $_[0];
my @return_loop;

my @tmp_vals;
my $i = 0 ;
foreach (@split) {
$i++;
if ($i == $#split) {
push @tmp_vals, { Value => $_, isLast => 1 };
} else {
push @tmp_vals, { Value => $_};
}

}

if ($tmp_vals[0]) {
my $num;
if ($#tmp_vals > 0) { $num = 1; }
return { outputted => \@tmp_vals, outputted_number => $num };
}
}

..then call with:

Code:
<%your_global_name($Eng_Title)%>
<%if outputted.length%>
<h2>English Title<%if outputted_number%>s<%endif%></h2>
<%loop outputted%>
<%if isLast%> and <%endif%><i><%Value%></i>
<%endloop%>
<%endif%>

That should do the job :)

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] Help With Global In reply to
Another one Tongue

Quote:
<%if last%> and <%endif%>

With this you can check that this is the last record from loop Wink

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Help With Global In reply to
I thought they stopped that tag? (at least, it did on one of my fresh installs I was working on last week, and tried using that)

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] Help With Global In reply to
Well, works on mines ... v. 3.2.0 all of them.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Help With Global In reply to
Mmm ok - I'll take your word =) Maybe was a typo, or somehing when I tried it =)

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: [eupos] Help With Global In reply to
Oh, man, am I happy! Yep- works GREAT!

Thank you both!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Help With Global In reply to
Ah I just noticed the Adrian reply, a good one ... way better explained than mine and nice, and short global too.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [carfac] Help With Global In reply to
OK, I am probably pushing my luck here.... but it works.... unless there is only one item in the list.

Here is what I used for the template:


<%if last%> and <%endif%>"<i><%Value%></i><%if last%>.<%else%>,<%endif%>"

For multiple items, sweet:

English Titles: "Legend of the White Serpent," "Tale of the White Serpent," "Panda and the Magic Serpent," and "The White Snake Enchantress."

But with just ine, that "and" gets stuck in there like this:

Alternate Title: and "Hakujaden."
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [eupos] Help With Global In reply to
I just saw Adrians, too. I tried it, but do NOT get any results. I get the English Title: only...
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Help With Global In reply to
Oops, fixed the code - it wasn't returning an array ref.

Adrian
Quote Reply
Re: [brewt] Help With Global In reply to
Thanks Adrian. It is a think of beauty (especially compared to the uglyness that was my code!)
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Help With Global In reply to
Updated it again (the plural form needs to check that it's > 1).

Adrian
Quote Reply
Re: [brewt] Help With Global In reply to
Sorry, I am not getting it. What do I name the global in Adrian's example?
dave

Big Cartoon DataBase
Big Comic Book DataBase
> >