Hola,
I’ve got a bit of a problem with an array of mine.
[php]
$menu = array(
‘category’ => array(
‘icon’ => ‘fa fa-bars’,
‘title’ => ‘<?php if ($title == constant("my-account") || $title == constant("password") || $title == constant("email-address") || $title == constant("logout")) { echo class=active } ?>’,
‘description’ => ‘<?php constant("account-overview-title"); ?>’,
‘class’ => ‘<?php if ($title == constant("my-account") || $title == constant("password") || $title == constant("email-address") || $title == constant("logout")) { echo class=active } ?>’,
‘links’ => array (
‘icon’ => ‘fa fa-user’,
‘title’ => ‘<?php if ($title == constant("my-account")) { echo "id="current""; } echo "href="'.URLADDR.'account-overview/my-account/""; echo "title="constant("my-account-title");"" ?>’,
‘description’ => ‘<?php constant("my-account") ?>’))
);
foreach ($menu as $section => $items) {
$cIcon = $items[‘icon’];
$cTitle = $items[‘title’];
$cDesc = $items[‘description’];
$cClass = $items[‘class’];
$lIcon = $items[‘links’][‘icon’];
$lTitle = $items[‘links’][‘title’];
$lDesc = $items[‘links’][‘description’];
[/php]
I just want to focus on one part for now - once that’s fixed all the rest will fall in line.
Check out the value of “title” beneath “category” - It’s an if statement that dictates when that particular element should be given the class “active” in order to give the appearance of that category being selected.
Let me just say, the original code works perfectly fine, but I want to use an array because it’s really quite a bit of code just for one menu. An array is the most efficient way to reduce the size of this code.
$cTitle is called a couple lines down, here:
[php]<li <?php var_export($cTitle, TRUE) ?>>[/php]
In browser source, it appears like this:
<li >
I change how $cTitle is introduced:
[php]<li <?php echo $cTitle; ?>>[/php]
In browser source, it appears like this:
[php]<li <?php if ($title == constant("my-account") || $title == constant("password") || $title == constant("email-address") || $title == constant("logout")) { echo class=active } ?>>[/php]
My first thought for a solution was to remove the PHP from the title key, put the PHP back in the foreach loop, and then put the constant values (my-account, password, email-address, etc.) as my values for multiple title keys, but the problem is that other “categories” may have less or more constants than the one I’ve included here.
tl;dr - My array values that contain PHP are outputting plain text instead of the code used to determine one thing or another.
I can provide the full source or a link to a working version online, I just don’t want to make the post too cluttered to see clearly.
Any help is much appreciated.
Thanks,
awl19