Automate the css versioning in smarty(2.6) - css

I need to force CSS changes to go live immediately and I found that add a version to CSS would help to do that as bellow.
<link rel="stylesheet" href="css/style.css?version=123456" media="all"/>
I need to automate this as it is difficult to change the main file always when need to do small change to css file.
So I found following line of code(sample) in PHP doing the same job.
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
I have tried to convert this line to Smarty, but it is giving error.
code :
<link rel="stylesheet" href="css/style.css?version={#filemtime:css/style.css} />
error:
syntax error: unrecognized tag: #filemtime:...........
Anybody has an idea how to do this ?
Thanks in advance

You can add this modifier to smarty plugin folder,
function smarty_modifier_filemtime($path){
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
return filemtime( YOUR_HOME_DIR.$path );
}
then call it like bellow,
<link rel="stylesheet" href="/css/style.css?v={'/css/style.css'|#filemtime}" type="text/css">

Related

use custom css by wordpress subfolder?

I'm using the polylang plugin. Additional css is required for the arabic language. How can I run css according to the subfolder in the functions?
example:
//This is your own css file
<link rel="stylesheet" href="/yellow.css" type="text/css" media="screen,projection" />
//this is the code that will also work according to subfolders
<?php if( url(www.example.com/ar) ) ?>
<link rel="stylesheet" href="/blue.css" type="text/css" media="screen" />
<?php endif;?>
If your trying to fetch styles for a page in php.
Try this
<!--Styles included -->
<style>
<?php include '/blue.css'?>
</style>
wp_enqueue_style('theme', PLUGIN_URL . '/assets/css/test.css');
Another
function load_admin_script() {
wp_enqueue_style('theme', DSSLIDER_PATH . 'assets/css/test.css');
}
add_action( 'admin_enqueue_scripts', 'load_admin_script' );

TinyButStrong and CSS

I'm trying to create a website MVC with PHP and TinyButStrong. Everything works just fine except that CSS code does not work with TinyButStrong. Anyone knows the problem here?
file example.html
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
</head>
<body>
<p>[onshow.msg]</p>
</body>
file php
<?php
include "tbs_class.php";
$tbs = new clsTinyButStrong;
$msg = "example tbs";
$tbs->LoadTemplate("example.html");
$tbs->Show();
?>

Adding CSS design file to an existing MVC Project

I have a simple MVC project and I want to start design it with CSS file,
I created a Style/StyleSheet.css file with this content:
body {
background-color:green;
}
and added the link to it inside _Layout.cshtml, with this line:
<link href="#Url.Content("~/Style/StyleSheet.css")" rel="stylesheet" type="text/css" />
I don't see any change of the background color, what am I doing wrong ?
Help will be Appreciated ! Thanks !
Try basic html:
<link href="/Style/StyleSheet.css" rel="stylesheet" type="text/css" />
or change "..." inside the string to '...' :
<link href="#Url.Content('~/Style/StyleSheet.css')" rel="stylesheet" type="text/css" />

Difference between base_url scenarios

I am a bit confuse about the difference between the two url scenarios like
$config['base_url'] = '';
$config['base_url'] = 'localhost/blabla';
<link rel="stylesheet" type="text/css" href="<?php echo base_url(). 'css/style.css'; ?>" />
If I will set the base_url() as on the first given the site would apply the css but if I set it to the second given example the css would not apply and the browser logs could not found(404) but it has the same generated url like
localhost/blabla/css/style.css
WHY? i am reading the documentation in elislab website but cant figure it out. Any input guys..
$config['base_url'] = '';
$config['base_url'] = 'localhost/blabla';
Try this, should work for the both above:
<?php
$this->load->helper('url');
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url()?>/css/style.css" />

wordpress and hardcoded domain names in URL

I just installed Wordpress, and one thing I discovered is that site URL appears to be hardcoded in all the generated HTML.
For example, I see things like:
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="http://www.mywebserver.com/wp- content/themes/twentyeleven/style.css" />
<link rel="pingback" href="http://www.mywebserver.com/xmlrpc.php" />
Is there a way to tell Wordpress to strip out the domain name in the generated URLs? For example, I would prefer:
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="/wp-content/themes/twentyeleven/style.css" />
<link rel="pingback" href="/xmlrpc.php" />
A couple links of code can fix it, in your functions file and header file: Fix absolute links in Wordpress
Functions.php
function fix_links($input) {
return preg_replace('!http(s)?://' . $_SERVER['SERVER_NAME'] . '/!', '/', $input);
}
Header.php -- before you output any HTML
ob_start('fix_links');

Resources