Array Block

Permalink
Hi,

I need to put my images below into an array and save it as a variable.

Can any one show me any guidance please..?

Thanks

<img src="<?php  echo $field_1_image->src; ?>">
<img src="<?php  echo $field_2_image->src; ?>">

 
Mnkras replied on at Permalink Reply
Mnkras
you mean like
$images = array();
$images[] = $field_1_image;
$images[] = $field_2_image;

?

its in an array with the variable $images
obaudains replied on at Permalink Reply
Excellent.

I need to output the array in the <head> , so can I use the variable $images to do this..?
obaudains replied on at Permalink Reply
Sorry in the header
Mnkras replied on at Permalink Reply
Mnkras
I do not know totally what you are trying to do,do you want to do this then:

foreach($images as $image) {
    echo '<img src="'.$image->src.'"/>';
}
mkly replied on at Permalink Reply
mkly
Are you trying to save this in the database between page loads?
obaudains replied on at Permalink Reply
No, I need to force it into the header and output the array in a JavaScript snipped in the head of the document. I can do it with cold fusion bug am unsure if this is schievable with php
mkly replied on at Permalink Reply
mkly
Ahhh... Ok still a little blurry but I think we're getting closer to understanding each other.

Are you creating a "Block" as it's called in Concrete5?

If so you can do this in your controller.php

// in controller.php
// on_page_view gets called when someone views
// the page. You can't put this in view() because
// it gets called after the head of the document is
// written
public function on_page_view() {
  // I'm still not quite sure where you are
  // getting these values from.
  // if it's from the blocks db table then
  // you could do this.
  $images = array();
  // since we are in the controller not the view
  // we use $this
  $images[] = $this->field_1_image;
  $images[] = $$this->field_2_image;


Still might not be completely sure what you are asking. Hopefully that helps a bit.