Jump to content

php accordion content help


samoht

Recommended Posts

hello all,

 

I am trying to create a module for the backend user that will enable them to specify titles and contents to be displayed in an accordion.

 

I want to give them the option of having the titles above each content pane (like a traditional accordion) or besides the content panes.

I have created my module for the most part - and have the traditional set up working fine, but I would like to clean it up a little.

 

First, I would like to loop through all the items to see which is active.

<?php
//Collect Parameters
$layout=$params->get('layout');

$headercol=$params->get('headercol');
$headercolbg=$params->get('headercolbg');


$item1=$params->get('item1');
$item2=$params->get('item2');
$item3=$params->get('item3');
$item4=$params->get('item4');
$item5=$params->get('item5');
$item6=$params->get('item6');
$item7=$params->get('item7');
$item8=$params->get('item8');
$item9=$params->get('item9');
$item10=$params->get('item10');

$title1=$params->get('title1');
$title2=$params->get('title2');
$title3=$params->get('title3');
$title4=$params->get('title4');
$title5=$params->get('title5');
$title6=$params->get('title6');
$title7=$params->get('title7');
$title8=$params->get('title8');
$title9=$params->get('title9');
$title10=$params->get('title10');


$code1=$params->get('code1');
$code2=$params->get('code2');
$code3=$params->get('code3');
$code4=$params->get('code4');
$code5=$params->get('code5');
$code6=$params->get('code6');
$code7=$params->get('code7');
$code8=$params->get('code8');
$code9=$params->get('code9');
$code10=$params->get('code10');

 

this retrieves the info from the module. $item will be a booleen 0 or 1 to determine if they want to use that content in the accordion.

 

echo '<script type="text/javascript">
window.addEvent("domready", function(){
		var accordion = new Accordion("h5.atStart", "div.atStart", {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle("color", "'.$headercol.'");
			},

			onBackground: function(toggler, element){
				toggler.setStyle("color", "'.$headercolbg.'");
			}
		}, $("accordion"));



	}); 


</script>';

This is the js code that will be inserted. (I'm not sure this will work for the accordion with the titles on the side?)

 

then a little condition to see if we are "on top" or "besides"

if($layout==1){

 

Currently this is how I have the code for the accordion with titles on top:

if($item1==1){
echo '


<h5 class="toggler atStart">'.$title1.'</h5>
<div class="element atStart">
	'.$code1.'
	</div>';

}

if($item2==1){
echo '...

 

rather than go through with a condition on each item I would like to setup an array that contains all my items with their booleen value then loop through the arrray to find the items I want to echo.

 

Then once I get that set up correctly - I can begin coding the output for the accordion with titles on the side.

 

Any ideas??

 

thanks

Link to comment
Share on other sites

I suppose to simplify my first question I could ask this way:

 

how do get the information from my other variables if I make an array for the $items like:

$myItems = array($item1,$item2,$item3,$item4,$item5,$item6,$item7,$item8,$item9,$item10);
foreach( $myItems as $myItem) {
  if($myItem==1){
     //this is where I need to echo my title and code but I don't know how to match it with the item?
  }
}

 

Dose this make sense?

Link to comment
Share on other sites

ok I solved the loop issue like this:

 

<?php
$row1 = array($params->get('item1'),$params->get('title1'),$params->get('code1'));
$row2 = array($params->get('item2'),$params->get('title2'),$params->get('code2'));
$row3 = array($params->get('item3'),$params->get('title3'),$params->get('code3'));
$row4 = array($params->get('item4'),$params->get('title4'),$params->get('code4'));
$row5 = array($params->get('item5'),$params->get('title5'),$params->get('code5'));
$row6 = array($params->get('item6'),$params->get('title6'),$params->get('code6'));
$row7 = array($params->get('item7'),$params->get('title7'),$params->get('code7'));
$row8 = array($params->get('item8'),$params->get('title8'),$params->get('code8'));
$row9 = array($params->get('item9'),$params->get('title9'),$params->get('code9'));
$row10 = array($params->get('item10'),$params->get('title10'),$params->get('code10'));

if($layout==1){
//Place user snippets in accordion structure
$myitems = array($row1,$row2,$row3,$row4,$row5,$row6,$row7,$row8,$row9,$row10);

echo '<div id="accordion" style="margin-top:'.$margintop.'px;margin-bottom:'.$marginbottom.'px">';
foreach ($myitems as $myitem){
	if($myitem[0]==1) {
		echo '
				<h5 class="toggler atStart">'.$myitem[1].'</h5>
				<div class="element atStart">
					'.$myitem[2].'
				</div>';
	}
}	
}
else {
$myitems = array($row1,$row2,$row3,$row4,$row5,$row6,$row7,$row8,$row9,$row10);

echo '<div id="submenu">';
echo '<h3 class="sub">Treatments</h3>';
	foreach ($myitems as $mytitle){
		if($mytitle[0]==1) {
			echo '<h5 class="toggler atStart">'.$mytitle[1].'</h5>';
		}
	}	
echo '</div>';
echo '<div class="page_text">';

	foreach ($myitems as $mypanel){
		if($mypanel[0]==1) {
			echo '<div class="element atStart">'.$mypanel[2].'</div>';
		}
	}		
echo '</div>';	
}

 

which loads everything properly - but the js for the accordion does not work if the title menu is beside the panels

 

Any pointers on how to fix this? - I would really like to have the js code work for both positions.

 

I realize that this is not really a php question now, sorry

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.