Jump to content

Echoing AIOM "String" in template


louisstephens
 Share

Recommended Posts

I wasnt quite sure where to post this (perhaps the AIOM thread is the correct place, if so I am sorry).. But I have a switch statement set up on certain values in an options. I have that part working like a charm.. However, when I echo:

      echo "<link rel=\"stylesheet\" href=\"{AIOM::CSS(array('styles/style.css', 'styles/slider.css', 'styles/style2.css', 'styles/style4.css'));}\">";

It just returns a link. It is like it is rendering one linked file and I receive a 404 error. DId I escape the "" the wrong way?

 

switch ($switchColor) {
    case "Style3":
      echo "<link rel=\"stylesheet\" href=\"{echo AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/style3.css'));}\">";
      break;

    case "Style4":
      echo "<link rel=\"stylesheet\" href=\"{echo AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/style4.css'));}\">";
      break;

    default:
      echo "<link rel=\"stylesheet\" href=\"{echo AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/normal.css'));}\">";

  }

I should have actually tried assigning it to a variable and then passing that in to the switch before I posted this. I solved it by assigning the AIOM array to a variable.  So apparently that isnt working either.

Edited by louisstephens
Link to comment
Share on other sites

My personal opinion is: this is uggly code, hard to read, hard to maintain. I would do it more like this:

switch($switchColor) {
    case "Style3":
        $cssLink = AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/style3.css'));
        break;

    case "Style4":
        $cssLink = AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/style4.css'));
        break;

    default:
        $cssLink = AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/normal.css'));
}
echo "<link rel='stylesheet' href='{$cssLink}' />";

 

To be honest, it could be made a bit more readable:

$myStyles = array('styles/style1.css', 'styles/slider.css', 'styles/style2.css');

if('Style3' == $switchColor) {
    $myStyles[] = 'styles/style3.css';
} else if('Style4' == $switchColor) {
    $myStyles[] = 'styles/style4.css';
} else {
    $myStyles[] = 'styles/normal.css';
}

$cssLink = AIOM::CSS($myStyles);
echo "<link rel='stylesheet' href='{$cssLink}' />";

// ----------------------------------------------------
// or just ?
echo "<link rel='stylesheet' href='" . AIOM::CSS($myStyles) . "' />";
// or ?
echo '<link rel="stylesheet" href="' . AIOM::CSS($myStyles) . '" />';

 

  • Like 5
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...