|
List Info
Thread: Quick question re: laying out elements over two columns
|
|
| Quick question re: laying out elements
over two columns |

|
2008-02-17 15:44:55 |
Hi ho,
Stuck on an apparently straightforward task (must need more
coffee!).
I've got a typical "Section cover" story that is
using:
my $stories = $m->comp(
'/util/archive_list.mc',
...to retrieve a list of related stories by category. Then
I'm using a
typical:
% for my $art ( $stories) {
... do something
% }
To iterate over the results, etc.
However, what I'd like to do is to divide the resulting
number of
stories in half and put 1..(x)/2 in one div and (x)/2..x in
another,
to achieve a two-column layout. The whole exercise of
thinking about
that made me harken back to the default templates that are
usually
installed with Bricolage, which reference placing elements
in a table
row. Here I'm not using tables -- just the first half of the
results
in one div and the remaining results in the next. I can see
some yucky
ways of doing that using the "offset" argument and
passing it to /util/
archive_list.mc -- but that doesn't seem like the
"right" way to do it.
Any help (to get me past my Sunday haze) appreciated.
Best,
Phillip.
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-17 16:32:18 |
On Sun, Feb 17, 2008 at 04:44:55PM -0500, Phillip Smith
wrote:
>
> Hi ho,
>
> Stuck on an apparently straightforward task (must need
more coffee!).
> I've got a typical "Section cover" story that
is using:
>
> my $stories = $m->comp(
> '/util/archive_list.mc',
>
> ...to retrieve a list of related stories by category.
Then I'm using a
> typical:
>
> % for my $art ( $stories) {
> ... do something
> % }
>
> To iterate over the results, etc.
>
> However, what I'd like to do is to divide the resulting
number of
> stories in half and put 1..(x)/2 in one div and
(x)/2..x in another,
I'm not 100% sure I'm following, but if you capture the
value of the array in a scalar, it will report the number of
elems.
ie: my $num_elems= stories; my $halfway=$num_elems/2; my
$div="div1 info";
my $elem_count=1
for my $art ( stories) {
if ($elem_count>$halfway){$div="div2 stuff"}
++$elem_count;
...do stuff
}
Am I understanding you question, and does that work?
> to achieve a two-column layout. The whole exercise of
thinking about
> that made me harken back to the default templates that
are usually
> installed with Bricolage, which reference placing
elements in a table
> row. Here I'm not using tables -- just the first half
of the results
> in one div and the remaining results in the next. I can
see some yucky
> ways of doing that using the "offset"
argument and passing it to /util/
> archive_list.mc -- but that doesn't seem like the
"right" way to do it.
>
> Any help (to get me past my Sunday haze) appreciated.
>
> Best,
>
> Phillip.
>
> --
> Phillip Smith,
> Simplifier of Technology
> Community Bandwidth
> http://www.community
bandwidth.ca
>
>
>
--
Brad Harder,
Method Digital Logic
http://www.methodlogic.net
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-17 17:08:15 |
On Sun, Feb 17, 2008 at 02:32:18PM -0800, bharder wrote:
> On Sun, Feb 17, 2008 at 04:44:55PM -0500, Phillip Smith
wrote:
> >
> > Hi ho,
> >
> > Stuck on an apparently straightforward task (must
need more coffee!).
> > I've got a typical "Section cover" story
that is using:
> >
> > my $stories = $m->comp(
> > '/util/archive_list.mc',
> >
> > ...to retrieve a list of related stories by
category. Then I'm using a
> > typical:
> >
> > % for my $art ( $stories) {
> > ... do something
> > % }
> >
> > To iterate over the results, etc.
> >
> > However, what I'd like to do is to divide the
resulting number of
> > stories in half and put 1..(x)/2 in one div and
(x)/2..x in another,
>
> I'm not 100% sure I'm following, but if you capture the
value of the array in a scalar, it will report the number of
elems.
>
> ie: my $num_elems= stories; my $halfway=$num_elems/2; my
$div="div1 info";
Might want to adjust $halfway for floats, too, and do a:
$halfway+=0.5; $halfway=sprintf("%.0f",$halfway);
and then...
> my $elem_count=1
open <div> here...
> for my $art ( stories) {
> if ($elem_count>$halfway){$div="div2
stuff"}
replace above with:
if ($elem_count == $halfway {[close first div, open
second]}
> ++$elem_count;
> ...do stuff
> }
>
> Am I understanding you question, and does that work?
>
> > to achieve a two-column layout. The whole exercise
of thinking about
> > that made me harken back to the default templates
that are usually
> > installed with Bricolage, which reference placing
elements in a table
> > row. Here I'm not using tables -- just the first
half of the results
> > in one div and the remaining results in the next.
I can see some yucky
> > ways of doing that using the "offset"
argument and passing it to /util/
> > archive_list.mc -- but that doesn't seem like the
"right" way to do it.
> >
> > Any help (to get me past my Sunday haze)
appreciated.
> >
> > Best,
> >
> > Phillip.
> >
> > --
> > Phillip Smith,
> > Simplifier of Technology
> > Community Bandwidth
> > http://www.community
bandwidth.ca
> >
> >
> >
>
> --
>
> Brad Harder,
> Method Digital Logic
> http://www.methodlogic.net
--
Brad Harder,
Method Digital Logic
http://www.methodlogic.net
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-17 19:15:27 |
On Sun, Feb 17, 2008 at 03:08:15PM -0800, bharder wrote:
> On Sun, Feb 17, 2008 at 02:32:18PM -0800, bharder
wrote:
> > On Sun, Feb 17, 2008 at 04:44:55PM -0500, Phillip
Smith wrote:
> > >
> > > Hi ho,
> > >
> > > Stuck on an apparently straightforward task
(must need more coffee!).
> > > I've got a typical "Section cover"
story that is using:
> > >
> > > my $stories = $m->comp(
> > > '/util/archive_list.mc',
> > >
> > > ...to retrieve a list of related stories by
category. Then I'm using a
> > > typical:
> > >
> > > % for my $art ( $stories) {
> > > ... do something
> > > % }
> > >
> > > To iterate over the results, etc.
> > >
> > > However, what I'd like to do is to divide the
resulting number of
> > > stories in half and put 1..(x)/2 in one div
and (x)/2..x in another,
> >
> > I'm not 100% sure I'm following, but if you
capture the value of the array in a scalar, it will report
the number of elems.
> >
> > ie: my $num_elems= stories; my
$halfway=$num_elems/2; my $div="div1 info";
Phillip and I discussed this a bit in #bricolage on
irc.perl.org, so I'm just posting what happened there to the
mailing list:
What I wrote _did_ do the trick (so I understood the
question properly), and Phillip asked (in irc) what I was
trying to do w/ the "open close div thing" (which
it looks like he figured out by himself).
For the benefit of anybody else who might find this useful,
though, the idea was to open the "first div"
before entering the loop, and at the $halfway mark, close
that first div and open the second, continuing processing
the rest of the story elements. What I left off is that
the second div will probably need to be closed after leaving
the foreach loop (erroneously called a "for" loop
in the sample code we were using.
so roughly:
stories; #<-- array holding the stories in
question
$num_stories = stories; # counts the number of stories
automagically by perl's array->scalar conversion
# calculate halfway point, round to integer. 0.5 is added
for int-rounding,
# 1 is added to get first story of second <div>. Total
== 1.5
$start_next_div = $num_stories/2; $start_next_div+=1.5;
$start_next_div=sprintf("%.0f",$start_next_div);
$story_count=1;
[do your first div setup here]
foreach $single_story ( stories) {
if ($story_count == $start_next_div) {
[close first div, start second]
}
[do your own processing...]
++$story_count;
}
[do your second div closing-work here]
HTH,
> Might want to adjust $halfway for floats, too, and do
a:
> $halfway+=0.5;
$halfway=sprintf("%.0f",$halfway);
>
> and then...
>
> > my $elem_count=1
>
> open <div> here...
>
> > for my $art ( stories) {
> > if ($elem_count>$halfway){$div="div2
stuff"}
> replace above with:
>
> if ($elem_count == $halfway {[close first div, open
second]}
>
> > ++$elem_count;
> > ...do stuff
> > }
> >
> > Am I understanding you question, and does that
work?
> >
> > > to achieve a two-column layout. The whole
exercise of thinking about
> > > that made me harken back to the default
templates that are usually
> > > installed with Bricolage, which reference
placing elements in a table
> > > row. Here I'm not using tables -- just the
first half of the results
> > > in one div and the remaining results in the
next. I can see some yucky
> > > ways of doing that using the
"offset" argument and passing it to /util/
> > > archive_list.mc -- but that doesn't seem
like the "right" way to do it.
> > >
> > > Any help (to get me past my Sunday haze)
appreciated.
> > >
> > > Best,
> > >
> > > Phillip.
--
Brad Harder,
Method Digital Logic
http://www.methodlogic.net
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-17 19:42:21 |
On 17-Feb-08, at 8:15 PM, bharder wrote:
> Phillip and I discussed this a bit in #bricolage on
irc.perl.org, so
> I'm just posting what happened there to the mailing
list:
>
> What I wrote _did_ do the trick (so I understood the
question
> properly), and Phillip asked (in irc) what I was trying
to do w/ the
> "open close div thing" (which it looks like
he figured out by
> himself).
>
> For the benefit of anybody else who might find this
useful, though,
> the idea was to open the "first div" before
entering the loop, and
> at the $halfway mark, close that first div and open the
second,
> continuing processing the rest of the story
elements. What I left
> off is that the second div will probably need to be
closed after
> leaving the foreach loop (erroneously called a
"for" loop in the
> sample code we were using.
>
>
> so roughly:
Might as well share the final that I used too... (Brad,
please avert
your eyes -- incoming kludgey code!):
% my $halfway=$limit/2; # I decided to use the limit that I
was
passing to /util/archive_list.mc vs. the counting the number
of
elements in the array.
% my $elem_count=0; # I also wanted to start my count at
0, which
is the 1st element returned in the array.
<div id="1"> <!-- open the 1st div
-->
% for my $art ( $stories) {
... get the data / values / properties you need from the
story being
returned
% ++$elem_count;
% if ($elem_count<$halfway) {
... do stuff (in the first div)
% } elsif ($elem_count==$halfway) {
</div> <!-- close the 1st div (if
necessary) -->
<div id="2"> <!-- open the 2nd div
(if necessary) -->
% } elsif ($elem_count>$halfway) {
... do stuff (in the second div)
% }
% }
</div> <!-- close either div -->
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-17 21:41:41 |
On Sun, Feb 17, 2008 at 08:42:21PM -0500, Phillip Smith
wrote:
>
> On 17-Feb-08, at 8:15 PM, bharder wrote:
>
> >Phillip and I discussed this a bit in #bricolage on
irc.perl.org, so
> >I'm just posting what happened there to the mailing
list:
> >
> >What I wrote _did_ do the trick (so I understood
the question
> >properly), and Phillip asked (in irc) what I was
trying to do w/ the
> >"open close div thing" (which it looks
like he figured out by
> >himself).
> >
> >For the benefit of anybody else who might find this
useful, though,
> >the idea was to open the "first div"
before entering the loop, and
> >at the $halfway mark, close that first div and open
the second,
> >continuing processing the rest of the story
elements. What I left
> >off is that the second div will probably need to be
closed after
> >leaving the foreach loop (erroneously called a
"for" loop in the
> >sample code we were using.
> >
> >
> >so roughly:
>
>
> Might as well share the final that I used too... (Brad,
please avert
> your eyes -- incoming kludgey code!):
>
> % my $halfway=$limit/2; # I decided to use the limit
that I was
> passing to /util/archive_list.mc vs. the counting the
number of
> elements in the array.
> % my $elem_count=0; # I also wanted to start my
count at 0, which
> is the 1st element returned in the array.
>
> <div id="1"> <!-- open the 1st div
-->
> % for my $art ( $stories) {
>
> ... get the data / values / properties you need from
the story being
> returned
>
> % ++$elem_count;
> % if ($elem_count<$halfway) {
>
> ... do stuff (in the first div)
>
> % } elsif ($elem_count==$halfway) {
>
> </div> <!-- close the 1st div
(if necessary) -->
> <div id="2"> <!-- open the 2nd
div (if necessary) -->
>
> % } elsif ($elem_count>$halfway) {
>
> ... do stuff (in the second div)
>
> % }
> % }
Phillip, you'll be missing one of your stories with the
above tests (at the "halfway" mark)...
you have:
if less than half, do processing
if == half, process <div> switch (!!but no indication
of processing)
if more than half, do processing...
If this is correct (and even if not, but it's a matter of
style), I'd change it to:
# $halfway_point calculated above....
# <div> opened above
$which_half=1; $story_count=0;
foreach $story ( stories) {
if ($story_count == $halfway_point) {
$which_half=2; [close first div, open second];
}
if (1 == $which_half) {
[do processing in "first half" manner]
} else {
[do processing in other manner ("second half",
obviously)]
}
++$story_count;
}
# close second <div>, continue on...
> </div> <!-- close either div -->
>
>
--
Brad Harder,
Method Digital Logic
http://www.methodlogic.net
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-17 21:48:02 |
On 17-Feb-08, at 10:41 PM, bharder wrote:
> Phillip, you'll be missing one of your stories with the
above tests
> (at the "halfway" mark)...
Heh. You're right! Thanks for
that!
Phillip.
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-28 17:26:44 |
On Feb 17, 2008, at 19:48, Phillip Smith wrote:
>> Phillip, you'll be missing one of your stories with
the above tests
>> (at the "halfway" mark)...
>
> Heh. You're right! Thanks for
that!
Example for buildingbrics.com?
David
|
|
| Re: Quick question re: laying out
elements over two columns |

|
2008-02-29 13:09:17 |
On 28-Feb-08, at 3:26 PM, David E. Wheeler wrote:
> On Feb 17, 2008, at 19:48, Phillip Smith wrote:
>
>>> Phillip, you'll be missing one of your stories
with the above
>>> tests (at the "halfway" mark)...
>>
>> Heh. You're right! Thanks for
that!
>
> Example for buildingbrics.com?
Heh. Nice one. Will post asap.
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
[1-9]
|
|