Mailing List Archive

Is there a better way to get a single element?
I have a story with exactly 4 sections in it.
Each section gets called individually.

I currently use this approach to get at each of the 4 sections.
my @homepageSections = $element->get_elements("section");
$burner->display_element( $homepageSections[0] );
$burner->display_element( $homepageSections[1] );
$burner->display_element( $homepageSections[2] );
$burner->display_element( $homepageSections[3] );


Is there a better way to access each section? Perhaps something like:
$burner->display_element( $element->get_element("section")[0] );

I don't see get_element in the docs, so I don't think that is possible, but it would be nice if there were a way to reference a specific element in the story instead of iterating through to find it.

Thanks for the consideration,
Adam
Re: Is there a better way to get a single element? [ In reply to ]
On 5 September 2011 21:37, Adam Wilson <adam@rfxtechnologies.com> wrote:

> I have a story with exactly 4 sections in it.
> Each section gets called individually.
>
> I currently use this approach to get at each of the 4 sections.
> my @homepageSections = $element->get_elements("section");
> $burner->display_element( $homepageSections[0] );
> $burner->display_element( $homepageSections[1] );
> $burner->display_element( $homepageSections[2] );
> $burner->display_element( $homepageSections[3] );
>
>
> Is there a better way to access each section? Perhaps something like:
> $burner->display_element( $element->get_element("section")[0] );
>

HI Adam,

Try:

my @homepageSections = $element->get_elements("section");
foreach (@homepageSections) {
$burner->display_element( $_ );
}

Adeola
Re: Is there a better way to get a single element? [ In reply to ]
On 6 September 2011 02:09, Adeola Awoyemi <adeola@creativeadea.com> wrote:

>
>
> On 5 September 2011 21:37, Adam Wilson <adam@rfxtechnologies.com> wrote:
>
>> I have a story with exactly 4 sections in it.
>> Each section gets called individually.
>>
>> I currently use this approach to get at each of the 4 sections.
>> my @homepageSections = $element->get_elements("section");
>> $burner->display_element( $homepageSections[0] );
>> $burner->display_element( $homepageSections[1] );
>> $burner->display_element( $homepageSections[2] );
>> $burner->display_element( $homepageSections[3] );
>>
>>
>> Is there a better way to access each section? Perhaps something like:
>> $burner->display_element( $element->get_element("section")[0] );
>>
>
> HI Adam,
>
> Try:
>
> my @homepageSections = $element->get_elements("section");
> foreach (@homepageSections) {
> $burner->display_element( $_ );
> }
>
>
Or for a shorthand version you can say:

$burner->display_element( $_ ) foreach @homepageSections;
RE: Is there a better way to get a single element? [ In reply to ]
Adeola,
Thanks for the tip, but I was thinking there might be a way to get to a particular element without having to loop through the array. My example was a poor one, because I wouldn't really have done it that way.

Here would be a better example.

>> $burner->display_element( $homepageSections[2] );
>> $burner->display_element( $homepageSections[1] );
>> $burner->display_element( $homepageSections[0] );
>> $burner->display_element( $homepageSections[3] );

Adam

-----Original Message-----
From: users@lists.bricolagecms.org [mailto:users@lists.bricolagecms.org] On Behalf Of Adeola Awoyemi
Sent: Monday, September 05, 2011 9:14 PM
To: users@lists.bricolagecms.org
Subject: Re: Is there a better way to get a single element?

On 6 September 2011 02:09, Adeola Awoyemi <adeola@creativeadea.com> wrote:

>
>
> On 5 September 2011 21:37, Adam Wilson <adam@rfxtechnologies.com> wrote:
>
>> I have a story with exactly 4 sections in it.
>> Each section gets called individually.
>>
>> I currently use this approach to get at each of the 4 sections.
>> my @homepageSections = $element->get_elements("section");
>> $burner->display_element( $homepageSections[0] );
>> $burner->display_element( $homepageSections[1] );
>> $burner->display_element( $homepageSections[2] );
>> $burner->display_element( $homepageSections[3] );
>>
>>
>> Is there a better way to access each section? Perhaps something like:
>> $burner->display_element( $element->get_element("section")[0] );
>>
>
> HI Adam,
>
> Try:
>
> my @homepageSections = $element->get_elements("section");
> foreach (@homepageSections) {
> $burner->display_element( $_ );
> }
>
>
Or for a shorthand version you can say:

$burner->display_element( $_ ) foreach @homepageSections;
Re: Is there a better way to get a single element? [ In reply to ]
Ok I see what you're trying to do. Only problem is you need a way to order the elements and also I don't think you can get to the elements w/o first doing a get_elements('something') call. Then you can use get_value() on the returned elements to render them.

See docs for advanced templates here: http://bricolagecms.org/docs/devel/api/Bric/AdvTemplates.html

HTH,
Adeola

On 6 Sep 2011, at 02:49, Adam Wilson <adam@RFXTechnologies.com> wrote:

> Adeola,
> Thanks for the tip, but I was thinking there might be a way to get to a particular element without having to loop through the array. My example was a poor one, because I wouldn't really have done it that way.
>
> Here would be a better example.
>
>>> $burner->display_element( $homepageSections[2] );
>>> $burner->display_element( $homepageSections[1] );
>>> $burner->display_element( $homepageSections[0] );
>>> $burner->display_element( $homepageSections[3] );
>
> Adam
>
> -----Original Message-----
> From: users@lists.bricolagecms.org [mailto:users@lists.bricolagecms.org] On Behalf Of Adeola Awoyemi
> Sent: Monday, September 05, 2011 9:14 PM
> To: users@lists.bricolagecms.org
> Subject: Re: Is there a better way to get a single element?
>
> On 6 September 2011 02:09, Adeola Awoyemi <adeola@creativeadea.com> wrote:
>
>>
>>
>> On 5 September 2011 21:37, Adam Wilson <adam@rfxtechnologies.com> wrote:
>>
>>> I have a story with exactly 4 sections in it.
>>> Each section gets called individually.
>>>
>>> I currently use this approach to get at each of the 4 sections.
>>> my @homepageSections = $element->get_elements("section");
>>> $burner->display_element( $homepageSections[0] );
>>> $burner->display_element( $homepageSections[1] );
>>> $burner->display_element( $homepageSections[2] );
>>> $burner->display_element( $homepageSections[3] );
>>>
>>>
>>> Is there a better way to access each section? Perhaps something like:
>>> $burner->display_element( $element->get_element("section")[0] );
>>>
>>
>> HI Adam,
>>
>> Try:
>>
>> my @homepageSections = $element->get_elements("section");
>> foreach (@homepageSections) {
>> $burner->display_element( $_ );
>> }
>>
>>
> Or for a shorthand version you can say:
>
> $burner->display_element( $_ ) foreach @homepageSections;
Re: Is there a better way to get a single element? [ In reply to ]
On Sep 5, 2011, at 6:49 PM, Adam Wilson wrote:

> Adeola,
> Thanks for the tip, but I was thinking there might be a way to get to a particular element without having to loop through the array. My example was a poor one, because I wouldn't really have done it that way.

# Get the fourth section container element:
my $section = $element->get_ container(section => 3);

Details here:

http://bricolagecms.org/docs/current/api/Bric::Biz::Element#Public-Class-Methods

Best,

David