Gossamer Forum
Quote Reply
Divide column to two
I want to display the column Description in a new way. Now I use the nl_2_br so it insert <br> when there is an enter. I want to continue use this global but to divide the text in the Description column to two something like Description1 Description2.
Text 1 will be the text form the begging of the text up to the first <br><br>
The 2 will be the text that is after the <br><br> up to the end
It like the Trim_Field.
Quote Reply
Re: [nir] Divide column to two In reply to
Hi,

Totally untested - but give this a go:

Global name: split_into_2_descs

Code:

Code:
sub {
use POSIX qw(ceil);
my $desc = $_[0];

my @split = split / /, $desc;

if ($#split < 1) {
return { Description1 => $desc, Description2 => '' }
}

my $split_into = ceil($#split / 2);


my ($desc1,$desc2);
for (my $i = 0; $i <= $#split; $i++) {
if ($i <= $split_into) { $desc1 .= " " . $split[$i]; } else { $desc2 .= " " . $split[$i]; }
}

return { Description1 => $desc1, Description2 => $desc2 }

}

Call with:

Code:
<%split_into_2_descs($Description)%>
<%Description1%> and <%Description2%>

If the description is only 1 word or less, it will just return the value into <%Description1%>

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] Divide column to two In reply to
Hi Andy, Thanks

It not split the text in after the first break, I think it splits the text in the middle, can you do it that it will splits the text after the first break.
Like-
Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg

Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56


So that the first paragraph will be Description1
Quote Reply
Re: [nir] Divide column to two In reply to
Hi,

Right, so you want to split in up by paragraph?

i.e:

Quote:
bla bla bla
bla bla bla
bla bla bla
bla bla bla

bla bla bla
bla bla bla
bla bla bla
bla bla bla
bla bla bla

..would give:

Description1 =>

Quote:
bla bla bla
bla bla bla
bla bla bla
bla bla bla

Description2 =>


Quote:
bla bla bla
bla bla bla
bla bla bla
bla bla bla
bla bla bla

??

If so, whats gonna happen when there more than just 2 paragraphs?

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] Divide column to two In reply to
Hi,

Assuming there is only ever going to be 1 or 2 paragraph, this will work:

Global name: get_desc1_and_desc2

Code:
sub {
my @in = split /\n\n/, $_[0];
return { Description1 => $in[0], Description2 => $in[1]}
}

Call with:

Code:
<%get_desc1_and_desc2($Description)%>
<h2>Paragraph 1: </h2>
<pre><%Description1%></pre>
<%if Description2%>
<h2>Paragraph 2: </h2>
<pre><%Description2%></pre>
<%endif%>

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] Divide column to two In reply to

Hi
There will be two or more paragraph, the first paragraphs need to be Description1 and from the second paragraph up to the end (3 4 5 .. paragraphs) will be the Description2

Quote Reply
Re: [nir] Divide column to two In reply to
Hi,

Try this:

Global name: get_desc1_and_desc2

Code:
sub {
my @in = split /\n\n/, $_[0];

my $desc1 = $in[0];

shift @in;

my $desc2 = join("\n\n", @in);

return { Description1 => $desc1, Description2 => $desc2 }
}

Call with:

Code:
<%get_desc1_and_desc2($Description)%>
<h2>Paragraph 1: </h2>
<pre><%Description1%></pre>
<%if Description2%>
<h2>Paragraph 2: </h2>
<pre><%Description2%></pre>
<%endif%>

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!
Quote Reply
Re: [Andy] Divide column to two In reply to
HiIt didn’t success to split.
Quote Reply
Re: [nir] Divide column to two In reply to
Hi,

How are you calling it?

How are your paragraphs split? Can you paste an example

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] Divide column to two In reply to
HiI call it like you write.An example isSmile
Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfgSdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfgSdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg

Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg

Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg

Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg

Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg Sdfdf345dfg

Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56 Sdfg sdfg sdfgsdfg sdg sdfg sdg sdfgsdg56
Quote Reply
Re: [nir] Divide column to two In reply to
Hi,

Try this:

Global name: get_desc1_and_desc2

Code:
sub {
my @in = split /\n\r?\n\r?/, $_[0];
my $desc1 = $in[0];
shift @in;
my $desc2 = join("\n\n", @in);
$desc2 =~ s|\n\n|<br /><br />|sg;
return { Description1 => $desc1, Description2 => $desc2 }
}

Call with:

Code:
<%get_desc1_and_desc2($Description)%>
<h2>Paragraph 1: </h2>
<%Description1%>
<%if Description2%>
<h2>Paragraph 2: </h2>
<%Description2%>
<%endif%>

Just tested this on my development installation - and it works fine =)

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] Divide column to two In reply to
Tanks AndySmile
Quote Reply
Re: [Andy] Divide column to two In reply to
Code:
my @in = split /\n\r?\n\r?/, $_[0];

Um, I think you mean \r?\n\r?\n

And what is the point of joining using \n\n and then substituting with <br><br>. Why not just use <br> in the first place? Tongue

Code:
sub {

my @parts = split /\r?\n\r?\n/, $_[0];
my $desc1 = shift @parts;
my $desc2 = join "<br /><br />", @parts;

return { Description1 => $desc1, Description2 => $desc2 }
}

Last edited by:

Wychwood: Jun 24, 2008, 4:51 PM