[eluser]1cookie[/eluser]
Hi
From a project I was working on a colleague was using a tricky piece of code to loop through some stylesheets initialized in the calling controller, like thus:
Code:
// header.tpl
{* CSS *}
{foreach from=$ci->page_info.css item=css_file}<link type="text/css" rel="stylesheet" href="/assets/css?from={$css_file}&_t=admin" />{/foreach}
And my calling controller:
Code:
// page.php
class Page extends MY_Controller {
public function __construct() {
parent::__construct();
$this->page_info['css'][] = "admin.css";
$this->page_info['css'][] = "reset.css";
}
public function index(){
$this->smarty->view("admin/home.tpl", (array)$data);
}
}
Naturally my full view/template would look something like:
Code:
// admin/home.tpl
{include file="header.tpl"}
<!-- content here -->
{include file="footer.tpl"}
Problem is:
Code:
href="/assets/css?from={$css_file}&_t=admin"
doesn't build the correct HTML links? From Firebug:
Code:
<link href="/assets/css?from=reset.css&_t=admin" rel="stylesheet" type="text/css">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /assets/css</title>
</head>
<body>
<h1>Index of /assets/css</h1>
<table>
<tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="/assets/">Parent Directory</a></td><td> </td><td align="right"> - </td><td> </td></tr>
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="admin.css">admin.css</a></td><td align="right">2014-03-15 15:08 </td><td align="right">268 </td><td> </td></tr>
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="style.css">style.css</a></td><td align="right">2014-03-11 14:32 </td><td align="right">4.1K</td><td> </td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
<address>Apache/2.4.6 (Ubuntu) Server at localhost Port 80</address>
</body></html>
</link>
This is simply Apache displaying the contents of '/assets/css'. Do you understand how the above would build the correct HTML links? i.e.
Code:
<link type="text/css" rel="stylesheet" href="/assets/css/admin.css&_t=admin" />
<link type="text/css" rel="stylesheet" href="/assets/css/style.css&_t=style" /> etc...
Have you seen this technique used before?
Just to add to that, I *can* loop through the above array successfully in my view. For example:
Code:
{foreach from=$ci->page_info.css item=css_file}{$css_file}{/foreach}
will print:
Code:
// admin/home.tpl
admin.css style.css etc...
in the browser.