Welcome Guest, Not a member yet? Register   Sign In
Page specific CSS for site
#1

[eluser]erichg[/eluser]
I need to have separate css files for certain pages. How do I include a separate stylesheet for a page. I have a header template with all of the css and js includes in there, but I want one for a specific page. Any help would be great.
#2

[eluser]InsiteFX[/eluser]
Use different header views.
#3

[eluser]erichg[/eluser]
What do you mean by header views?
#4

[eluser]erichg[/eluser]
Could I just put an if statement based on the channel to embed the css link? I was just thinking about this.
#5

[eluser]InsiteFX[/eluser]
layout_view.php
Code:
$this->load->view('header_view');
$this->load->view('content_view');
$this->load->view('footer_view');

$data = array(
    'title' => 'My Title',
    'css'  => 'app.css'
);

$this->load->vars($data);
$this->load->view('layout_view');

You break the html document up into the three views.

But you could also do it with an if statement but then you injecting pgp code into the document.
#6

[eluser]Aken[/eluser]
Combining your CSS into a single file is a better idea.
#7

[eluser]rana[/eluser]
For this type of situation, I have integrated following logic on my codeigniterplus project, check if that helps in any way:

1) application follow a standard for view pages. a view for a specific controller function is placed as views/{controller_name}/{controller_function_name}.tpl .
2) I have applied same technique to load page specific css/js files. on header, the pseudo code can be like this:

Code:
{if file_exists(APPATH."../styles/".$controller_name."/".$view".css")}
    <link type="text/css" rel="stylesheet" href="{$base_url}../styles/.{$controller_name}/{$view}.css" />
{/if}
#8

[eluser]erichg[/eluser]
I used this to do what I wanted:

Code:
{if segment_1=='segment'}<link rel="stylesheet" href="{site_url}/css/2013.css">{/if}
#9

[eluser]CroNiX[/eluser]
Akens solution is really the best. That way, one CSS file loads for all of your site and then no matter what page they go to next the css is already loaded and cached, which will speed displaying the site up over having multiple css sheets that get loaded on different pages.




Theme © iAndrew 2016 - Forum software by © MyBB