Welcome Guest, Not a member yet? Register   Sign In
Stylesheet link with url changed
#1

[eluser]jem88[/eluser]
Hi sleepless developers!
I 've to link to the stylesheet from a the page of a blog that show the complete post, and I've fragmented the views in 'header' , 'menu', 'page_content' (that have the name of the specific page) and 'footer'.
The problem is that the link i include in the header, that linked the stylesheet in assets folder run for all the views, except this, cause I add to the url the title and the id of the current post (so I can take it from the db when clicking 'read more'). What path should I use to link the same folder but having this modified url?

this is the link i used for all views:
<link rel="stylesheet" href="../assets/style.css" type="text/css" media="screen" title="no title" charset="utf-8"/>

Thanks!!!

#2

[eluser]Otemu[/eluser]
Hi,

To link stylesheets you could just use:

Code:
<link rel=“stylesheet” href=”<?php base_url(’/assets/style.css’) ?> type=“text/css” media=“screen” title=“no title” charset=“utf-8”/>

Nowadays it common practice to have all styles in one stylesheet to reduce http requests, so you could include your styles in your asset sheet, or use a bundle technique, if you need to use another stylesheet then there many ways you can add check out this topic

#3

[eluser]jem88[/eluser]
Thanks for answer,
I haven't a base url setted, so I set that as 'http://localhost:8888/be_Smart/application', and write in header the code you suggest me, but seems not run... i think is the base url not correct, right?
How should i write it?
#4

[eluser]Otemu[/eluser]
Hi,

You can set base url in the config application\config\config.php make sure you autoload the url helper \application\config\autoload.php

Code:
$autoload['helper'] = array('url');

Typically you should have a structure like below:

-www root
- -be_Smart
- - -application
- - -system
- - -assets
- - - -css
- - - - -style.css

Using this structure your base url would be http://localhost:8888/be_Smart or just /be_Smart
So to target you CSS path you would use
Code:
<?php base_url(’/assets/css/style.css’) ?>;

Or to target it without base you would use http://localhost:8888/be_Smart/assets/css/style.css

If your site still includes the index.php when navigating to your pages example http://localhost:8888/be_Smart/index.php/home then use site_url() instead of base_url()
#5

[eluser]jem88[/eluser]
Sorry, but I'm very not able to solve this problem.
I have loaded the url helper, (automatically), I set the base_url as you write, and I put this as css path
Code:
<link rel="stylesheet" href="<?php base_url('/assets/style.css'); ?>"  type="text/css" media="screen" title="no title" charset="utf-8"/>
But, it doesn't work!! I can't understand why.
Thanks
#6

[eluser]jem88[/eluser]
Sorry, but I'm very not able to solve this problem.
I have loaded the url helper, (automatically), I set the base_url as you write, and I put this as css path
Code:
<link rel="stylesheet" href="<?php base_url('/assets/style.css'); ?>"  type="text/css" media="screen" title="no title" charset="utf-8"/>
But, it doesn't work!! I can't understand why.
Thanks
#7

[eluser]Otemu[/eluser]
When you view source in your browser what is the url that is displayed??
#8

[eluser]jem88[/eluser]
is this,
Code:
href="http://localhost:8888/be_Smart/assets/style.css"
and is correct, maybe I badly explained, this link now run for pages like
Code:
http://localhost:8888/be_Smart/blog
, but when I from the blog click on 'read more' button, as I explain in first post, this add to url some code, the url become like this:
Code:
http://localhost:8888/be_Smart/complete_post/post/9
, where complete_post is my controller, and post is the function at which I passed the id of the post to load from db!
#9

[eluser]jem88[/eluser]
And i'm fucking stupid! I've forgot that before I try to made a different header for that controller, only for test if it run, and I've not changed the header that were load by complete_blog! Now it perfectly run, thank you very much for help! Smile




Theme © iAndrew 2016 - Forum software by © MyBB