codesleeve asset pipeline not compiling or concatenating except on local - php

I am using Codesleeve Asset Pipeline in Laravel 4 to serve my css and js files.
Unfortunately it does not want to compile bootstrap in a staging environment.
This is the config:
'paths' => array(
'app/assets/javascripts',
'app/assets/stylesheets',
'app/assets/images',
'lib/assets/javascripts',
'lib/assets/stylesheets',
'lib/assets/images',
'provider/assets/javascripts',
'provider/assets/stylesheets',
'provider/assets/images',
'vendor/twitter/bootstrap/less/',
'vendor/twitter/bootstrap/js/',
),
Those 3 lines are the only ones changed.
On my local instance it works fine, I get one css file including all of bootstrap and my own stuff, and one js file with jquery and the bootstrap plugins I asked for.
But on the staging server, I get this:
<link href="http://website.net/assets/vendor/twitter/bootstrap/less/bootstrap.less" rel="stylesheet" type="text/css">
<link href="http://website.net/assets/application.css" rel="stylesheet" type="text/css">
<script src="http://website.net/assets/jquery.min.js" ></script>
<script src="http://website.net/assets/vendor/twitter/bootstrap/js/button.js" ></script>
<script src="http://website.net/assets/vendor/twitter/bootstrap/js/dropdown.js" ></script>
<script src="http://website.net/assets/application.js" ></script>
I think that the asset pipeline is not even trying to concatenate or compile anything.

It turned out that the minifier was barfing on bootstrap 3's css, and not producing the file. However no error was thrown.

You need to add your staging server on the config asset-pipeline so it also compiles on this stage.

Related

php echo is not working in html

I am having some trouble getting a php value into a bootstrap button which is in html
This is my code:
<html>
<head>
<title>Samples</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>
<?php echo "Samples"; ?> Stuff
</body>
</html>
So instead of the button saying "Samples Stuff" - the button just simple says "Stuff". It is important that the button takes a php value as eventually I will be putting a db value in the button - but I can't even get the basics working
Why is it not working?
Are you running a locally hosted server. If not, you probably should install XAMPP. Ensure the file has a .php extension, I don't see any other reason why a simple echo would not work.
Make sure that the file extension ends with .php. Also make sure that your php/apache is configured correctly.
Try and look at your error logs and see if anything is there
Firstly ensure that your file extension is .php secondly make sure you run .php files on a php enabled webserver. Simply viewing php files on your browser will not actually compile the php. This is done in the back-end on your server.

How to include External CSS and JS file in Laravel 5

I am Using Laravel 5.0 , the Form and Html Helper are removed from this version , i dont know how to include external css and js files in my header file. Currently i am using this code.
<link rel="stylesheet" href="/css/bootstrap.min.css"> <!--- css file --->
<script type="text/javascript" src="/js/jquery.min.js"></script>
I think that the right way is this one:
<script type="text/javascript" src="{{ URL::asset('js/jquery.js') }}"></script>
Here I have a js directory in the laravel's app/public folder. There I have a jquery.js file. The function URL::asset() produces the necessary url for you. Same for the css:
<link rel="stylesheet" href="{{ URL::asset('css/somestylesheet.css') }}" />
Keep in mind that the old mehods:
{{ Form::script() }}
and
{{ Form::style() }}
are deprecated and will not work in Laravel 5!
Try it.
You can just pass the path to the style sheet .
{!! HTML::style('css/style.css') !!}
You can just pass the path to the javascript.
{!! HTML::script('js/script.js') !!}
Add the following lines in the require section of composer.json file and run composer update "illuminate/html": "5.*".
Register the service provider in config/app.php by adding the following value into the providers array:
'Illuminate\Html\HtmlServiceProvider'
Register facades by adding these two lines in the aliases array:
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade'
In laravel 5.1,
<link rel="stylesheet" href="{{URL::asset('assets/css/bootstrap.min.css')}}">
<script type="text/javascript" src="{{URL::asset('assets/js/jquery.min.js')}}"></script>
Where assets folder location is inside public folder
i use this way, don't forget to put your css file on public folder.
for example i put my bootstrap css on
"root/public/bootstrap/css/bootstrap.min.css"
to access from header:
<link href="{{ asset('bootstrap/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" >
hope this help
Place your assets in public directory and use the following
URL::to()
example
<link rel="stylesheet" type="text/css" href="{{ URL::to('css/style.css') }}">
<script type="text/javascript" src="{{ URL::to('js/jquery.min.js') }}"></script>
At first, you have to put your .css or .js files in the public folder of your project. You may create subfolders to it and move the files into the subfolder. Then you have to do the followings
<link rel="stylesheet" href="{{asset('css/your_css_file.css')}}">
<script src="{{asset('js/your_js_file.js')}}"></script>
In my example, I have created two subfolders called css and js. I put all of the .css and .js files in corresponding folders and use them where ever I want them. Thank you and hope this helps you.
There are many ways to include external css and js files as specified in below code but you can choose one of them, i have tested them all, they work the same.
<link rel="stylesheet" href="{{ asset('css/stylesheet.css') }}" /><!--Recommended-->
<link rel="stylesheet" href="{{ URL::asset('css/somestylesheet.css') }}" />
<link rel="stylesheet" href="{{ URL::to('css/otherstylesheet.css') }}" />
<link rel="stylesheet" href="{{ url('css/anotherstylesheet.css') }}" />
Maybe there are more ways to load it.
but keep in mind that if you are loading the css and js from other than a public folder then better to use Laravel mix.
{{ HTML::style('yourcss.css') }}
{{ HTML::script('yourjs.js') }}
Laravel 5.5 comes with mix , the replacement for Elixir, the external css(sass) can be extracted to resources/assets/css(sass) and import to app.css(scss) or give the correct path to your node_module folder that contains the library and can be used as
<link rel="stylesheet" href="{{ mix('css/app.css') }}" >
The same can be done for Javascript too .
Ok so I was able to figure out for the version 5.2. You will first need to create assets folder in your public folder then put css folder and all css files into it then link it like this :
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
Hope that helps!
CORRECT & SECURED WAY
If you have a external .css or .js file to add into your page!
My version : Laravel Framework 5.7
If you want to add a External .js file..
Copy your External codes.
Run command npm install in your terminal.
When the above command is executed you can see a folder named node_modules.
Then go to resources/js.
Open file app.js.
Scroll down to the bottom and paste your External JS.
Finally run command npm run dev in your terminal.
your scripts will be updated and its compiled and moved to public/js/app.js . by adding a .js file in public folder will not effect on your page.
If you want to add a External .css file..
Copy your External styles.
Run command npm install in your terminal.
When the above command is executed you can see a folder named node_modules.
Then go to resources/sass.
Open file app.scss.
Scroll down to the bottom and paste your External Styles.
Finally run command npm run dev in your terminal.
your scripts will be updated and its compiled and moved to public/css/app.css . by adding a .css file in public folder will not effect on your page.
Easiest and the safest way to add your external .css and .js.
Laravel JavaScript & CSS Scaffolding
YouTube Compiling Assets
First you have to install the Illuminate Html helper class:
composer require "illuminate/html":"5.0.*"
Next you need to open /config/app.php and update as follows:
'providers' => [
...
Illuminate\Html\HtmlServiceProvider::class,
],
'aliases' => [
...
'Form' => Illuminate\Html\FormFacade::class,
'HTML' => Illuminate\Html\HtmlFacade::class,
],
To confirm it’s working use the following command:
php artisan tinker
> Form::text('foo')
"<input name=\"foo\" type=\"text\">"
To include external css in you files, use the following syntax:
{!! HTML::style('foo/bar.css') !!}
I may be late to the party but it's easy to include JS and CSS the Laravel Way by simply using asset() function
e.g.
<link rel="stylesheet" href="{{ asset('css/app.css') }}" />
Hope that helps
I have been making use of
<script type="text/javascript" src="{{ URL::asset('js/jquery.js') }}"></script>
for javascript and
<link rel="stylesheet" href="{{ URL::asset('css/main.css') }}">
for css, this points to the public directory, so you need to keep your css and js files there.
It mostly happens due to laravel webpackmix is not yet executed
composer require laravel/ui
PHP artisan ui vue --auth //you can use vue boostrap --auth is to add the login paths and
npm install
if it's asking to run "npm fund" then do it
npm run dev
try this once again

How to include JS/CSS files into templates of Slim Framework?

I am developing a simple web app with Slim framework. I got stuck with a probably simple problem. I want to include static files (CSS and Javascript) into my template.
My project folder structure is as follows:
index.php //<=== where all the routing happens.
/flot
layout.css
jquery.js
....
/templates
first_template.php
My header of first_template.php contains:
<link href="../flot/layout.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="../flot/jquery.js"></script>
When I call the projects root url
http://localhost/xampp/ProjectX/
(I'm using XAMPP) the template shows up, but the css and javascript stuff is not working. The Google Chrome console shows:
GET http://localhost/xampp/ProjectX/flot/layout.css 404 (Not Found)
GET http://localhost/xampp/ProjectX/flot/jquery.js 404 (Not Found)
Any suggestions? I spent almonst one hour in googling, but the overall documentation of the Slim framework is still literally slim :)
I assume you are displaying your Template on the Project root (index.php), so you should remove the ../ from your Stylesheet and JS relative Paths:
<link href="flot/layout.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="flot/jquery.js"></script>

Joomla 2.5 not loading JS scripts through article?

In Joomla 2.5 I have installed DirectPHP, which I have used extensively in Joomla 1.6 to embed PHP in Joomla articles. It works very well. I usually just for one include in the article, like this:
<?php
include "my_cool_script.php";
?>
Then I make my code in my_cool_script.php. One thing I often do is include more JS or CSS scripts in the page, right through the article, but putting the following lines in my_cool_script.php:
<link rel="stylesheet" type="text/css" media="screen" href="/scripts/css/dark-hive/jquery-ui-1.8.21.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/scripts/css/ui.jqgrid.css" />
<script src="/scripts/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/scripts/js/jquery-ui-1.8.21.custom.min.js" type="text/javascript"></script>
<script src="/scripts/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="/scripts/js/jquery.jqGrid.src.js" type="text/javascript"></script>
This has always worked in the past, with Joomla 1.6. Now in the Joomla 2.5 install. The rest of the PHP and HTML is loading in the article, and there aren't any errors on the page as far as loading the scripts. I look at the HTML code and I can see the above lines written to the page, but I cannot access any of the jQuery functions, like the script was not loaded. I get an error when I try to use any jQuery syntax. I know this script was working, because I just moved it from another site, running joomla 1.5 to the new one, 2.5.
Does anyone know anything about why the scripts aren't loading?
EDIT
Well i guess the script was loading, but it didn't like that used the $ symbol. I changed them all to jQuery and it works.
I am not sure exactly why, but perhaps in my installation there is some conflict, and the $ symbol is being recognized as it usually does, signifying that we are dong jQuery. So I changed all the $ to jQuery in my PHP scripts and all the jQuery seems to be working now.
Mootools (Joomla's javascript default framework until version 2.5) also uses '$', so it's very easy to run into some complications if you're unaware you're running scripts relying on both frameworks side to side.
Having said that, you could use 'jQuery' instead of '$' and release '$' for everyone else using the jQuery.noConflict(); command.
Cheers.

Yii is not auto including jquery

I have a strange problem with Yii & Jquery:
When I open a page which uses ajax/jquery on localhost Yii does automatically add asset include calls to the of the page:
<link rel="stylesheet" type="text/css" href="/PATH/assets/f72b359d/style.css" />
<script type="text/javascript" src="/PATH/assets/2e442e1a/jquery.js"></script>
<script type="text/javascript" src="/PATH/assets/2e442e1a/jquery.cookie.js"></script>
However when I run same code on the server Yii does not do it hense no Jquery available.
I'd appreciate if someone could direct to a way to solve it.
It seems like you're not registering jQuery in the correct way. You must add the following line in /protected/views/layout/main.php before </head> tag:
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
It will load jQuery automatically. Remember, if the YII_DEBUG flag is on it will load non-minified version, when deactivated (on production) it will load minified version. Hope this will fix your problem.
If all is working on your local machine it might be a permission problems
Have you checked that /assets is writable on your server ?
Yii publishes the assets it needs at runtime in this directory

Categories