0

I am having some trouble getting my array to work correctly. I am pulling the params from my Joomla template and then using them on the main index file: Here is what I have so far:

This is held in an include file that I pull in first

//Social Icons $tbFacebook = $this->params->get('tbFacebook'); $tbTwitter = $this->params->get('tbTwitter'); $tbGoogle = $this->params->get('tbGoogle'); $tbLinkedIn = $this->params->get('tbLinkedIn'); $tbPinterest = $this->params->get('tbPinterest'); $tbYouTube = $this->params->get('tbYouTube'); $tbVimeo = $this->params->get('tbVimeo'); //Check all the text boxes for content and assign array information //This may be able to be handled differently but for simplicity I left it alone if ($tbFacebook != null) { $arrFacebook= array("href" => $tbFacebook, "title" => "Like Us On Facebook", "icon" => "<i class=\"fa fa-facebook".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbTwitter != null) { $arrTwitter = array("href" => $tbTwitter , "title" => "Follow Us On Twitter", "icon" => "<i class=\"fa fa-twitter".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbGoogle != null) { $arrGoogle = array("href" => $tbGoogle , "title" => "Follow Us On Google Plus", "icon" => "<i class=\"fa fa-google-plus".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbLinkedIn != null) { $arrLinkedIn = array("href" => $tbLinkedIn , "title" => "Connect With Us On LinkedIn", "icon" => "<i class=\"fa fa-linkedin".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbPinterest != null) { $arrPinterest = array("href" => $tbPinterest , "title" => "Pin Us On Pinterest", "icon" => "<i class=\"fa fa-pinterest".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbYouTube != null) { $arrYouTube = array("href" => $tbYouTube , "title" => "Watch Us On YouTube", "icon" => "<i class=\"fa fa-youtube".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbVimeo != null) { $arrVimeo = array("href" => $tbVimeo , "title" => "Watch Us On Vimeo", "icon" => "<i class=\"fa fa-vimeo-square fa-2x\"></i>", "target" => "blank"); }; //Create Social Array $arrSocial = array( $arrFacebook, $arrTwitter, $arrGoogle, $arrLinkedIn, $arrPinterest, $arrYouTube, $arrVimeo ); //Remove the empties foreach($arrSocial as $key => $value) { if (empty($value)) { unset($arrSocial[$key]); $arrSocial = array_values($arrSocial); }; } //Variable to determine fist item, incase its not phone $first = true; 

my Joomla code

<?php if ($this->countModules('footer_mobile')) : ?> <jdoc:include type="modules" name="footer_mobile" style="html5" /> <?php else : //Limit to the first 5 items for($i=0;$i<5;$i++){ if ( $first ) { $first = false; echo '<div class="col-xs-2 col-xs-offset-1"><a href="'.$arrMobileFooter[$i]["href"].'" title="'.$arrMobileFooter[$i]["title"].'" target="_'.$arrMobileFooter[$i]["target"].'" ">'.$arrMobileFooter[$i]["icon"].'</a></div>'; } else { echo '<div class="col-xs-2"><a href="'.$arrMobileFooter[$i]["href"].'" title="'.$arrMobileFooter[$i]["title"].'" target="_'.$arrMobileFooter[$i]["target"].'">'.$arrMobileFooter[$i]["icon"].'</a></div>'; }; }; endif; ?> 

When the file outputs it only will pull in the Facebook link, even though the for loop is creating the rest just not populating it:

<div class="col-xs-2 col-xs-offset-1"> <a href="https://www.facebook.com/pages/United-Methodist-Camp-Tekoa-Inc/304907509358" title="Like Us On Facebook" target="_blank"> <i class="fa fa-facebook-square fa-2x"></i> </a> </div> <div class="col-xs-2"> <a href="/" title="" target="_" "=""></a> </div> <div class="col-xs-2"> <a href="/" title="" target="_"></a> </div> <div class="col-xs-2"> <a href="/" title="" target="_"></a> </div> <div class="col-xs-2"> <a href="/" title="" target="_"></a> </div> 

Can someone please tell me what I am doing wrong?

1 Answer 1

1

I would guess that the problem is when you trying to manipulate $arrSocial inside the foreach. I would recommend that you rewrite this and only add the object to the array if they aren't null using $arrSocial[] = value for adding to an existing array.

Try this:

//Social Icons $tbFacebook = $this->params->get('tbFacebook'); $tbTwitter = $this->params->get('tbTwitter'); $tbGoogle = $this->params->get('tbGoogle'); $tbLinkedIn = $this->params->get('tbLinkedIn'); $tbPinterest = $this->params->get('tbPinterest'); $tbYouTube = $this->params->get('tbYouTube'); $tbVimeo = $this->params->get('tbVimeo'); $arrSocial = array(); if ($tbFacebook != null) { $arrSocial[] = array("href" => $tbFacebook, "title" => "Like Us On Facebook", "icon" => "<i class=\"fa fa-facebook".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbTwitter != null) { $arrSocial[] = array("href" => $tbTwitter , "title" => "Follow Us On Twitter", "icon" => "<i class=\"fa fa-twitter".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbGoogle != null) { $arrSocial[] = array("href" => $tbGoogle , "title" => "Follow Us On Google Plus", "icon" => "<i class=\"fa fa-google-plus".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbLinkedIn != null) { $arrSocial[] = array("href" => $tbLinkedIn , "title" => "Connect With Us On LinkedIn", "icon" => "<i class=\"fa fa-linkedin".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbPinterest != null) { $arrPinterest = array("href" => $tbPinterest , "title" => "Pin Us On Pinterest", "icon" => "<i class=\"fa fa-pinterest".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbYouTube != null) { $arrSocial[] = array("href" => $tbYouTube , "title" => "Watch Us On YouTube", "icon" => "<i class=\"fa fa-youtube".$varSquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbVimeo != null) { $arrSocial[] = array("href" => $tbVimeo , "title" => "Watch Us On Vimeo", "icon" => "<i class=\"fa fa-vimeo-square fa-2x\"></i>", "target" => "blank"); }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.