Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Accessing sub array in template


2 Posts   212 Views


Community Member, 33 Posts

26 August 2014 at 10:58am

Hi Guys,

I have an array i am passing to the template that looks like...
bookdates =
0 = 2014-08-26
1 = 2014-08-27

On my template i have..
<% loop $itemBookedOutDates %> $bookdates <% end_loop %>
but i can't seem to access the sub portions of the bookdates array? Normally i think it's would be something like print_r(bookdates[0]) etc to access that portion, but how do you do that in the template?



Community Member, 33 Posts

26 August 2014 at 5:35pm

So what i have - is a function to get the dates between ranges and returns them as an array.

I then wanted to put those dates into a bit of javascript on my template page.

Just can't seem to find a way to get the code to put the values on the page. Any help would be great thanks!

What i have so far...

   public function getItemBookedOutDates() {
      $Params = $this->getURLParams();
      $itemDatesBookedOutOn = new item_booking();
$itemDatesBookedOutOn = item_Booking::get()->filter(array(
            'Item' => $Params['ID']

      $DateList = new ArrayList();   
      foreach($itemDatesBookedOutOn as $item) {      

         $days = $this->createDateRangeArray($item->itemBookingFrom, $item->itemBookingTo);
         $item->DateUnavailable = $days;

      return $this->DateList;
   function createDateRangeArray($strDateFrom,$strDateTo)
      // takes two dates formatted as YYYY-MM-DD and creates an
      // inclusive array of the dates between the from and to dates.

      // could test validity of dates here but I'm already doing
      // that in the main script      

      $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2), substr($strDateFrom,0,4));
      $iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2), substr($strDateTo,0,4));
      if ($iDateTo >= $iDateFrom)
         array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
         while ($iDateFrom < $iDateTo)
            $iDateFrom += 86400; // add 24 hours
      return $aryRange;