I have added this below code for css reference.
JHTML::_('stylesheet', 'example.css', 'components/'._THISCOMPONENT.'/assets/css/');
It is working fine in local.But when i try to run it in the server, the css is not working due to this
output html css link
<link rel="stylesheet" href="/components/com_fms/assets/css/css-3391b7d3949af1560b9927c0c3a672b2.php" type="text/css" />
Do anyone have idea on solving this issue?
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
By default this code work correct if it is added in template-file (templates/my_fantastic_template/index.php)
Try this code:
$document =& JFactory::getDocument();
$document->addStyleSheet('components/'._THISCOMPONENT.'/assets/css/example.css');
I hope it will be helpfull.
Try using
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
instead
JHTML::_('stylesheet', 'example.css', 'components/'._THISCOMPONENT.'/assets/css/');
complet /templates/system/css/system.css with your url to the css file
Related
I am trying to use the PHP Framework CodeIgniter for a PHP project. I never used it before. According to its documentation I activated the helper URL and included the css link as shown below:
$autoload['helper'] = array('url');
<link rel="stylesheet" type="text/css"
href="<?php echo base_url();?>public/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css"
href="<?php echo base_url();?>public/css/style.css"/>
Unfortunately the page is not able to load the css. Obviously if I put the compiled CSS link the page is able to load it.
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
Base_url() does not add a trailing slash. You need a forward slash in between the PHP code and public in the link href.
Say your base url is /htdocs/website/, the way you currently have it set up would print out /htdocs/websitepublic/css/style.css.
Here is the fixed code:
<link rel="stylesheet" type="text/css" href="<?php echo base_url();>/public/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();>/public/css/style.css"/>
i have a source code of a CMS the cms back-end working perfectly but in front-end shows errors the css not working properly i was searching for the solution then find
<!-- language: lang-html -->
<link href="<?php echo $sitepath; ?>/Assets/css/bootstrap.css" rel="stylesheet" media="screen"/>
<link href="<?php echo $sitepath; ?>/Assets/css/font-awesome.min.css" rel="stylesheet"/>
<link href="<?php echo $sitepath; ?>/Assets/css/bootstrap-responsive.css" rel="stylesheet" media="screen"/>
<link href="<?php echo $sitepath; ?>/Assets/css/sitestyles.css" rel="stylesheet" media="screen"/>
has not fixed
and am try to fix in include.php file here is the include file
$sitepath="http://".$_SERVER['HTTP_HOST'];
//Replace with your domain name if you wish
//$sitepath="http://www.example.com";
this code working on my server but while use this code on my localhost xampp to change
$sitepath="http://localhost/cms".$_SERVER['HTTP_HOST'];
//Replace with your domain name if you wish
//$sitepath="http://www.example.com";
still shows the top code css not working the url shows
localhost/cms/localhost/index.php
like this what i do help please
I use XAMPP and CI 2.14
(I know it's sounds ridiculous, but...) I don't know how to refer to a css file from a view. I've read and tried a lot of examples but, obviously I do something wrong...
<link rel="stylesheet" href="<?php echo base_url();?>css/main.css" type="text/css" />
The base url is: http://localhost/myapp/
Where should I put then main.css file (now is in the webroot/myapp/css folder), and how to reference it from a codeigniter view?
create folder assets:
path is: /assets/css/your_file.css
<link rel="stylesheet" href="/assets/css/your_file.css" type="text/css" />
Try to put the css folder inside the application folder, like this:
/yourapp/application/css/
And then
<link rel="stylesheet" href="<?php echo base_url();?>application/css/main.css" type="text/css" />
I have a file called "header.php" that I am including on every page on my site and this file contains links to other files on my sever like css files, jquery plugins, etc.. and right now I am using absolute paths for those links so they will work with files that are not in the same directory as the header.php file and this works, but as you can see in the example below, things start to get really hard to manage if you your header.php file contains lot's of links (which mine does) so I would like to know if there are any other alternatives to using absolute paths in the header.php file like I have done here.
header.php
<?
$base_url = "http://example.com";
?>
<html>
<head>
<title> <? echo($title); ?> </title>
<link rel="stylesheet" type="text/css" href="<? echo($base_url); ?>/styles/some_css_file.css" media="all"/>
<link rel="stylesheet" type="text/css" href="<? echo($base_url); ?>styles/another_css_file.css" media="all"/>
<link rel="stylesheet" type="text/css" href="<? echo($base_url); ?>styles/another_css_file.css" media="all"/>
...
...
...
<script type="text/javascript" src="<? echo($base_url); ?>/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<? echo($base_url); ?>/scripts/some_jquery_plugin.js"></script>
<script type="text/javascript" src="<? echo($base_url); ?>/scripts/another_jquery_plugin.js"></script>
...
...
...
</head>
Some file which includes header.php
<?
$title = "some page title";
include("header.php");
?>
<body>
PAGE CONTENTS
</body>
</html>
Use the HTML base tag to define the base of your site.
<base href="<?php echo $base_url; ?>" />
<link rel="style.css" />
Absolute path is the way to go here. But, if you have a lot of links to print, it can be simplified by storing the paths in an array and looping through the array.
$base = "http://www.example.com/"
$links = array( "styles/file1.css", "styles/file2.css", ... );
foreach ( $links as $link ) {
echo '<link rel="stylesheet" href="' . $base . $link . '" type="text/css" media="all" />';
}
As a side note, what you have isn't great practice. It would be better and more efficient for you to try and combine some of those files as this will reduce the amount of HTTP requests the browser has to make to your server. http://developer.yahoo.com/performance/rules.html#num_http
I had the same doubt in one of my projects and i've done as the code bellow. As the paths start with "/", the file will be found based in the root directory and in this case isn't necessary to specify the domain, it will turn the things easier for maintenace and prevent problems if you will do rewrite of URLs using (mod_rewrite). Hope it can help you too!
<html>
<head>
<title> <? echo($title); ?> </title>
<link rel="stylesheet" type="text/css" href="/styles/some_css_file.css" media="all"/>
<link rel="stylesheet" type="text/css" href="/styles/another_css_file.css" media="all"/>
<link rel="stylesheet" type="text/css" href="/styles/another_css_file.css" media="all"/>
<script type="text/javascript" src="/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/scripts/some_jquery_plugin.js"></script>
<script type="text/javascript" src="/scripts/another_jquery_plugin.js"></script>
</head>
</html>
This is not a direct answer to your question, but it may help you.
If you are including that many css and JS files you should look into using Minify. Minify will take a bunch of css/js files and compress/combine them into one file, which will greatly speed up the loading of your site.
Using this could also help with your path concern, as you can specify directories and groups very easily.
You can find information about it here: Minify
I am new to php, but suspect there is a simple solution that I am not aware of.
I have made a template for the header on every page, but when the user loads pages the css page changes in relation to their current page.
How do I have php track how many levels up in a folder the user is so I can pull the css from anywhere in the website?
<link rel="stylesheet" href="../templates/css/css.css" type="text/css" />
That is my current link to css, but for a page further down in folders I need it to add additional ../
You should use an absolute path from the root of the website (note, no ".." just a "/"):
<link rel='stylesheet' href='/templates/css/css.css' type='text/css' />
Will always work, as long as your css is at:
http://yourwebsite.com/templates/css/css.css
you shouldn't be using a relative path then. Why not just do something like:
<link rel="stylesheet" href="http://www.mysite.com/templates/css/css.css" type="text/css" />
or
<link rel="stylesheet" href="/templates/css/css.css" type="text/css" />
or
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/templates/css/css.css" type="text/css" />
whichever suits your needs - since you may be working locally and have a strange file structure, or a shared style directory for example
The best method is to use:
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/templates/css/css.css" type="text/css" />