Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: users

Is there a better way to get a single element?

 

 

Bricolage users RSS feed   Index | Next | Previous | View Threaded


adam at RFXTechnologies

Sep 5, 2011, 1:37 PM

Post #1 of 6 (837 views)
Permalink
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


adeola at creativeadea

Sep 5, 2011, 6:09 PM

Post #2 of 6 (785 views)
Permalink
Re: Is there a better way to get a single element? [In reply to]

On 5 September 2011 21:37, Adam Wilson <adam [at] rfxtechnologies> 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


adeola at creativeadea

Sep 5, 2011, 6:13 PM

Post #3 of 6 (786 views)
Permalink
Re: Is there a better way to get a single element? [In reply to]

On 6 September 2011 02:09, Adeola Awoyemi <adeola [at] creativeadea> wrote:

>
>
> On 5 September 2011 21:37, Adam Wilson <adam [at] rfxtechnologies> 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;


adam at RFXTechnologies

Sep 5, 2011, 6:49 PM

Post #4 of 6 (785 views)
Permalink
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 [at] lists [mailto:users [at] lists] On Behalf Of Adeola Awoyemi
Sent: Monday, September 05, 2011 9:14 PM
To: users [at] lists
Subject: Re: Is there a better way to get a single element?

On 6 September 2011 02:09, Adeola Awoyemi <adeola [at] creativeadea> wrote:

>
>
> On 5 September 2011 21:37, Adam Wilson <adam [at] rfxtechnologies> 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;


adeola at creativeadea

Sep 5, 2011, 11:38 PM

Post #5 of 6 (789 views)
Permalink
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 [at] RFXTechnologies> 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 [at] lists [mailto:users [at] lists] On Behalf Of Adeola Awoyemi
> Sent: Monday, September 05, 2011 9:14 PM
> To: users [at] lists
> Subject: Re: Is there a better way to get a single element?
>
> On 6 September 2011 02:09, Adeola Awoyemi <adeola [at] creativeadea> wrote:
>
>>
>>
>> On 5 September 2011 21:37, Adam Wilson <adam [at] rfxtechnologies> 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;


david at kineticode

Sep 6, 2011, 10:39 AM

Post #6 of 6 (787 views)
Permalink
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

Bricolage users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.