Change directory of css in patternlab - php

I want to change the directory of the style.css file in the pattern lab setup, how and where do I do this? I have a whole booststrap sass project setup already and I want patternlab to use the current files for this projects.

You can add css and javascript files in the following file:
source/_patterns/00-meta/_00-head.mustache

Related

PHP - Use files for multiple sites

I manage multiple sites with the same structure and i am searching for a way to include some files from the same source to all of them.
Ex: footer, css files.
The websites are built with php using vars declared in other files, so linking, naming and other site specific info won't be a problem.
Thanks!
You can set a common include path (outside the document root) for all the files that you need to share between sites, and include the files from each of your sites that way: http://php.net/manual/en/ini.core.php#ini.include-path
eg if you set the include_path to have /var/www/lib and put your footer.php in there, then you can
include('footer.php');
in each of your sites and they will all use the footer from /var/www/lib/footer.php
one thing to watch is for css / js and img files - they need to be served from the document root, so you can only use this technique for php files.
[you may have to watch out for your open_basedir too]
Not sure that I understand what you are asking for but I did this multiple times and it works.
put all files you use (css headers,footers, etc) in the same root directory
at the top of your PHP files write include 'filename.php; (or .css, .html , whatever extension they have)

Linking file (stylesheets, script files, images and etc..)

I have a problem on linking files such as stylesheets, images, database connection file(db.php), script files and etc.. because they are located outside the file where they are included/linked.
For example assuming this is the location of the main file where everything will be called:
my website directory/admin/thefilewhereeverythingwillbecalled.php
in thefilewhereeverythingwillbecalled.php, I must call the db.php which is located outside the folder that contains thefilewhereeverythingwillbecalled.php
e.g. my website directory/-this is the directory where the db.php is located-/thefilewhereeverythingwillbecalled.php - ditto the style sheets and script.
However the stylesheets and script are in the folder cssandjs (contains all stylesheets and script files) which this folder are located before the location of the thefilewhereeverythingwillbecalled.php
e.g. my website directory/-here is where the cssandjs folder is located-/thefilewhereeverythingwillbecalled.php
Generally I'm just having a problem on linking files which is outside from the file where it called those files. Can someone give me an idea how to link it please?
I tried this:
../cssandjs/style.cssand ./cssandjs/jquery.js but none of them work
If I'm correct, it's 2 directories up. Try this :
../../cssandjs/style.css
This will work if /cssandjs/ is in your website directory.
You should be a bit more specific with your directory names instead of -here is where this is located-
Can't seem to figure out which are in the same folder.
try to include full path to the files.
Try referencing the files like including the directories and files with
$_SERVER['DOCUMENT_ROOT']."/dirName/file.ext";
or use relative paths "../dirnName/file.ext";
first method is preferred

How to correctly link files?

From my previous experience, I've almost always had problems with linking files with my website projects.
For example, linking CSS styles, Javascript files and including files in PHP. The problem is, that on my PC, the directory of my project was /www/project-name/ and when I put the project on a server, the directory would be just /www/. When I uploaded the project to a server, images wouldn't show, styles wouldn't work, database connections wasn't set, functions were not defined etc...
So my question is: What is the best and most efficient way to link/include files?
Something that will work no matter what the directory of the project is, and possibly, if I include project/includes/mysql.class.php in file1.php, and I move that file to a different directory, it would still properly include project/includes/mysql.class.php
You should use relative paths.
Instead of specifying the full path ('/www/project-name/includes/whatever.php'), use a path relative to the current location:
'./includes/whatever.php'
you can define the document root directory of project and then, include all files depending on it
put
define(DOC_ROOT, realpath(direname(__FILE__));
in your front controller, and when you have to include a file
include(DOC_ROOT . "/includes/file.php");
all frameworks uses this method
I'd suggest using a relative path (eg ../style.css or ../../style.css)
The ../ references the parent directory to the current file.
This is what I do, in general.
I use root relative urls inside html (e.g. src="/images/logo.jpg"). This way I can just copy the html from one page and past it in another without having to worry about the link not working becase the other page is inside a folder.
I relative urls in css, because all the resources I use inside the css, like images, I keep in the same folder as the css file (or a sub-directory of it). I mostly do this because it is shorter (url(img/background.jpg); vs. url(/css/img/background.jpg);). Minor added bonus is you could just copy the css folder to create a new theme based on the old one, without having to change all the urls in the css.
In PHP I use include($_SERVER['DOCUMENT_ROOT'] . '/includes/mysql.php');. You can just copy past the code into another file in another folder and it will still work.
The only time I rarely need to hardcode paths is inside htaccess.

Including a javascript file outside of doc root using zend framework

I'm trying to include a javascript file in a phmtl view script file using the zend framework. Both the javascript file and the phtml file are part of a php library and located outside the doc root folder of my project. So the file structure looks like
/var/www/vhosts/project/
/var/www/vhosts/libraries/my-lib/view/viewscript.phtml
/var/www/vhosts/libraries/my-lib/js/javascript.js
/var/www/vhosts/libraries/my-lib has been added to the PHP paths using set_include_path. In viewscript.phtml, I use the following line to include javascript.js.
<?php $this->headScript()->appendFile('js/javascript.js'); ?>
For some reason, javascript.js is not included, even if I specify the absolute path instead of a relative path. Instead, I get a whole copy of my webpage inside a tag in the head section. If I put javascript.js into the doc root folder /var/www/vhosts/project and change the appendFile() path, it works just fine. How can I include javascript outside of doc root?
Based on previous questions you've been asking I think your directories are something problematic for you.
here is a functionnal and secure example or directory organization for Zend Framework (partial)
var/
www/
vhosts/
otherproject/
project/
src/ <-- maybe some project src can be here and not in your libraries
htdocs/ <--- real apache document root
css/
js/
var/
log/
sessions/
etc/
doc/
libraries/
Zend/
my-lib/
js/
So apache documentRoot is /var/www/project/htdocs. Here we can find the index.php file, the only php file available on public access.
In htdocs/js & htdocs/css you can put some of your project js & css files. And then you've got the problem of css and js files of your external php libs that are now completly outside of the web root.
What I usually do is, like others have said here, links from external directories to the js directory inside the web root. But to be more precise and keep things well organized here what you should do there:
ln -s /var/www/project/libraries/my-lib/js /var/www/project/htdocs/js/my-lib
ln -s /var/www/project/libraries/my-lib/css /var/www/project/htdocs/css/my-lib
And you should do it for all external lib having files that should be in the document root.
This way the base url for the js files of my-lib is /js/my-lib/.
Do not fear of using symlinks (junctions on windows), you can even store them in subversion repository. Just check that your apache configuration allow symlinks (Options +FollowSymlinks)
The path provided in appendFile() is relative to the site's document root (eg, your 'public' folder). It will not pick up on the php include_path.
You could move the js file into the doc root, create a symbolic link to it in the doc root, or you could read the file using php and output it's contents as a <script> tag.
form your path , i can tell your are using linux
so you can use symlink like this :
ln -s /var/www/vhosts/libraries/my-lib/ /var/www/vhosts/project/mylib/
therefor you can append the files :
<?php $this->headScript()->appendFile('/mylib/js/javascript.js'); ?>
and tada , its done
The tag that will be added to the page is a reference for the browser where to look for the JavaScript file.
JavaScript is a client side language, it runs on the users computer and is interpreted there, so the user needs to be able to access the file, hence it needs to be inside the root path as the user (client) should not have access to your application dir.
You could save a PHP file in your doc root and use that to get your JS:
getJS.php (saved in the doc root):
<?php
header("Content-type: text/javascript");
include_once '/../var/www/vhosts/libraries/my-lib/js/someJSfile.js';
?>
Then in your code:
<?php
$this->headScript()->appendFile('getJS.php');
?>
You could include switches to include different JS files or whatever you wanted, I haven't tested this for functionality, but the file when clicked does get the contents of the JS file.
Note: If this is for security reasons, it won't take much to get the contents of the file the user wants!

Drupal theme won't read CSS file

I'm currently working on a drupal theme but keep having problems with getting the theme to read the damn css file. I started off theming with the Framework theme, I tried organising the files on there for example creating a subdirectory to store the CSS file, change the setting in the .info file so it knows it's in the css folder, but it won't read the damn file.
Fast forward a few days and I've got 60% of my theme styled and layout-ed, so decided to port everything into a new theme folder rather than the Framework theme folder. Organised the folders and files, but again it won't read the CSS file whether I put it in a subdirectory or in the same directory as the .info file. It somehow worked once, but then went and hasn't worked again.
I've tried clearing the cache etc, but to no avail.
I'm working on a local wamp server. Drupal is latest version 7.
Any ideas how to fix this problem?
Thank you
Wich version of Drupal you are using? In Drupal 6 this works fine:
/* mytheme.info */
stylesheets[all][] = assets/css/master.css
stylesheets[all][] = assets/css/typo.css
This files are in my Theme folder
Folder: MYTHEME
File: mytheme.info
Folder: assets
Folder: css
File: master.css
File: typo.css
I know this is a bit late but maybe it will help someone else.
I'm using Drupal 7 and I attempted to add a javascript and stylesheet file in a custom module in the .info file.
module.always.js
and
module.always.css
It would load the first but not the second. I even put the stylesheet above the script in the info file and it would still just load the first file. Thought it was the directory and tried adding quotes around the file paths but that did nothing. Also thought it was the extra . in the file name but that didn't matter either.
The only way I could get both files to load was to remove them from the .info file and add a drupal_add_js and drupal_add_css for these files in the module_init() function.
No clue why that is the case but at least there is a work around.

Categories