Zend Framework , Trouble with paths - css

I'm doing my first zend application, following the official user's guide, I set up a standard zend application (with zend studio 9 and ZF 1.11) and I want to add images and CSS stylesheets to my .phtml pages. When I put the css files in "myApplicationName/public/css" everything works fine, but when I try to put them in another directory such as "myApplicationName/application/layouts/css", they don't get considered,
what kind of paths should i use to link them to phtml pages?
I've tried relative paths, things like :
<link rel="stylesheet" type="text/css" media="screen" href="../../css/layout_look_like.css" />
and also :
<link rel="stylesheet" type="text/css" media="screen" href="/application/layouts/css/layout_look_like.css" />
but it doesn't seem to work,
I've also tried paths with $this->baseUrl(), but <?php echo $this->baseUrl();?> returns nothing.
thanks for help.

CSS, Images, and JS and any other publicly accessible static assets must live under the public folder as this is your web server DOCUMENT_ROOT (ie. http://yourdomain/). Beyond that you can use whatever structure you like.

Your CSS files should be inside the public directory. There should be no need to place them in your application directory. If you really need to do it, you could make a symbolic link to the public directory.
To include a CSS file (stored in the public directory) to your view/layout, use:
<?php echo $this->headLink()->appendStylesheet($this->baseUrl('/styles/basic.css')); ?>

You have to write like below mentioned code for your layout_look_like.css file
echo $this->headLink()->appendStylesheet($this->baseUrl('/css/layout_look_like.css'));

Related

Stylesheet path issue

I'm editing an app on my website but the style sheet is located in this path:
home/aib23/public_html/wp-content/themes/striking_r/assets/affiliate_app_css
what would the stylesheet look like for that path? This is what I thought it was:
<link rel="stylesheet" file://home/aib23/public_html/wp-content/themes/striking_r/assets/app_css" />
but it did not seem to work. Note that this stylesheet is placed within my wordpress theme folder.
Any help would be appreciated! Thanks in advance to those that contribute! :)
The link to your stylesheet can be relative, but in this case you can harness WordPress's built in functions to make your life easier, like so:
<?php get_stylesheet_directory() ?>
get_stylesheet_directory() will automatically return the directory where WordPress is looking for the stylesheet. For example, if your stylesheet was named styles.css, you might use something like this:
<link rel="stylesheet" type="text/css" href="<?php get_stylesheet_directory() ?>/styles.css">
You don't need to link the complete path to the file -- WordPress will take care of that for you.
This kind of path is local to the client system. So if I visit a page with this link it will look for your CSS file on my computer, at /home/aib23/public_html/wp-content/themes/striking_r/assets/app_css
Also, you need to use the href attribute in your link element in order for it to work.
I suggest you use a link relative to your web root - like this:
<link rel="stylesheet" href="/wp-content/themes/striking_r/assets/affiliate_app_css/myfile.css" />
Replace myfile.css with the name of your stylesheet.
When linking to your stylesheet, you can either do it relatively or absolutely. For instance, if you're linking to a stylesheet in the same directory as your HTML document, you can simply put
<link rel="stylesheet" href="style.css" />
If, however, you want to refer to a main stylesheet throughout many HTML documents, you may want to stick with an absolute path. In your case, something like this:
<link rel="stylesheet" href="/wp-content/themes/striking_r/assets/app.css" />
Please note: Your stylesheet file name should always end with .css. Additionally, all href paths start after the public_html folder in your specific case.

Linking multiple stylesheets

I am using a Dedicated Server.
In the web-hosting side, I have folders arranged like so.
html
forum
files
images
files
Equinox
index.php
header.php
footer.php
style
style.css
mc-multiplayer
style
style.css
index.php
header.php
footer.php
I am trying to get the index.php of mc-multiplayer to link to the css file in mc-multiplayer, but no matter what it keeps going to the style.css file in the html folder.
At first glance I would suggest using the following code:
<link rel="stylesheet" href="style/style.css">
Make sure to confirm that everything is cased/spelled correctly and that directories are correct. As Kevin Boucher suggested, it would help to know the link you're currently using.
from a page within the mc-multiplayer subdirectory (as long as a <base> element isn't overriding the directory context)
this might work (no prefix (such as / or ../) before style should maintain the current folder context, then style subdir then the file):
<link href="style/style.css" rel="stylesheet" />
this should definitely work (/ to start at the root of the site then into mc-multiplayer subdir then style subdir to the file):
<link href="/mc-multiplayer/style/style.css" rel="stylesheet" />

In eclipse dynamic web project, how to link css to jsp file in webcontent folder

In Eclipse, I created a Dynamic Web Project and a JSP file under WebContent folder. I also created a CSS file under the WebContent folder. Then I use <link rel="stylesheet" type="text/css" href="XXX.css"> in the JSP to link to the CSS file but when I run on web server (Tomcat) the CSS didn't apply. Can someone tell me why?
You must put your web project name before the address path of your css file
Example:
<link rel="stylesheet" href="/YourProjectName/XXX.css" type="text/css">
or in more dynamic way:
<link rel="stylesheet" href="${pageContext.request.contextPath}/XXX.css" />
Have fun :)
You can use: With style.css file in WEB-INF/jsp folder
<style type="text/css">
<%#include file="css/style.css" %>
</style>
NOTE
This however copies the entire source of the CSS file into the HTML
output of the JSP page. In other words, this is a server-side include,
not a client-side resource reference. So you effectively miss the
advantage that the browser can cache static resources and this way you
end up with a bandwidth waste because the very same CSS file is
embedded in every single page. In other words, a bad idea in terms of
performance and efficiency.
as #BalusC described in comment! you want to test your style.css file anyway, this is a solution.
you can use
<link rel="stylesheet" type="text/css" href="path/css">
You should restart eclipse so that it maps all css and javascript files again.
I worked for me.

How to display CSS files in Django blog?

i'm very confused about how to add css files to a blog a made on django following this tutorial: http://www.programmersbook.com/page/21/Django-Beginner-Tutorial-Part-I/
Basically, i want to add a css style sheet to my blog. I've looked around a bit and seen somethings about static and media files and urls. I read a bit about them on Django's website but coulnd't fully understand them.
So, could anyone kindly tell me how i should display:
<link rel="stylesheet" type="text/css" href="style.css" />
They styles work when i do it internally, but how do i show external stylesheets?
It's right in the Django docs, check here. Follow the instructions there and you will be able to use something like that:
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}style.css" />
EDIT:
You should sepearate you "static" files from your templates. So move all your .css, .js and images to one directory in your app (it's default name is /static). Honestly, everything is written in the link provided.

css javascript image in django

Maybe this question has been asked a lot,
but I still can't understand how to load CSS files when using django...
Please can anyone explain to me step by step how to load it?
Can I load the CSS file without the static folder or link, so I don't need to change the urls.conf but just setting in "setting.py" file?
(Sorry if my English is bad") :(
on local machine: you have to add:
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
on a server you don't (and more you shouldn't for security reasons) need the previous line.
So finally: here is my architecture:
project/
app1/
__init.py__
views.py
public/
site_media/
js/
example.js
css/
example.css
in my settings.py:
MEDIA_ROOT = '/thecompletepath/public/site_media/'
MEDIA_URL = '/site_media/'
and in my templates, i use:
<link rel="stylesheet" type="text/css" href="/site_media/css/example.css" media="screen" />
Just add a normal link tag to your template.
<link rel="stylesheet" type="text/css" href="http://example.com/path/to.file.css">
Unless you have a dynamic CSS file, you would not want to have it related to anything in urls.py. Likewise, if you're not using the media (static) folder, you don't need to change anything in settings.py. Just insert it into your HTML in the template.
If you don't want to use an external CSS file, of course, you can always just put <style> tags into your templates.

Resources