Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-12224

Add template method to assign block arrays

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.1.0-b1
    • 3.1.0-dev
    • Template Engine
    • None

      Currently assign_block_vars() is used to assign block template loops which requires to be called within foreach/for/etc loop to assign the whole block, like that:

      foreach ($block_arrays as $block_array)
      {
      	$template->assign_block_vars('blockname', array(
      		'TOKEN_1' => $block_array[0],
      		'TOKEN_2' => $block_array[1],
      		'TOKEN_3' => $block_array[2],
      	));
      }
      

      This makes it hard to change the data assigned to the template loop when it come to extensions, because you either have to create event within the PHP loop to add/change $block_array key=>value pairs, or to use tricks with alter_block_array() construction which is not even possible within event.

      The suggestion is to add one more (wrapper) template method which can take the whole 2-dimensional $block_arrays array as a parameter, which (the array) can be passed to event before being assigned to template block loop, like following:

      extract($phpbb_dispatcher->trigger_event('core.modify_template_block_vars', compact('$block_arrays')));
      $template->assign_block_vars_array('blockname', $block_arrays);
      

      The wrapper function itself would be looking like that:

      	public function assign_block_vars_array($blockname, array $block_vars_array)
      	{
      		foreach($block_vars_array as $vararray)
      		{
      			$this->assign_block_vars($blockname, $vararray);
      		}
      		return true;
      	}
      

      This can make the core a little bit more expendable from the point of developing extensions.

            nickvergessen Joas Schilling
            rxu rxu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: