I want to test for the user's browser. If Internet Explorer, then this paragraph. else this paragraph.
How do I do that in a django html template?
Thanks!
Don't do it using Django. Use conditional comments. Example:
<!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->
Django templates are rendered on the server side, what actually goes to the browser is the output is the rendered template. So you can't write browser specific code in the template, unless you capture that information from the request, pass it as a variable to the template, when you render it, which then uses that value to produce browser specific code.
Don't. There should almost never be a need for this. If you really really think you need it, use IE's conditional comments.
Related
Is there is way to automatically switch the default template used in joomla based on the users browser? For instance, I am currently using Gantry framework for one of my websites, it would be a tonne of work to accommodate IE6, 7 and 8 into this framework, I was wondering if there's a script that will detect the users browser, say IE7, and if the user is using this browser Joomla automatically switches to a template that is compatible with that browser?
Yes, there is a way, it is called "Conditional Comments".
Conditional comments are a special type of HTML comments that work as conditions, and they are mostly used to check Internet Explorer version (because of css-compatibility).
Vocabulary:
lte: less than or equal to
gte: greater than or equal to
lt: less than
gt: greater than
!: not
This is the use of conditional comments:
<!--[if <something from vocabulary> IE <version>]>
code
<![endif]-->
Let's see some examples
<!--[if IE]>
You are certainly running Internet Explorer<br />
<![endif]-->
<!--[if !IE]>
You are certainly NOT running Internet Explorer<br />
<![endif]-->
<!--[if IE 6]>
You are certainly running Internet Explorer version 6<br />
<![endif]-->
<!--[if lte IE 6]>
You are certainly running Internet Explorer and it's version is lower or equal to 6<br />
<![endif]-->
<!--[if gte IE 6]>
You are certainly running Internet Explorer and it's version is greater or equal to 6<br />
<![endif]-->
<!--[if lt IE 6]>
You are certainly running Internet Explorer and it's version is lower than 6<br />
<![endif]-->
<!--[if gt IE 6]>
You are certainly running Internet Explorer and it's version is greater than 6<br />
<![endif]-->
it would be a tonne of work to accommodate IE6, 7 and 8 into this framework
In fact, joomla templates are made of some css files, named template.css, template.ie6.css, template,ie7.css, etc.
this is not a tonne of work, because the template.css contains the FULL template css, and template.ie#.css files contains only those rules which need to be overrided in order to work with a specific version of IE.
Then, in the template index file, there are some Conditional Comments that switch the css according to the browser you are using
SOURCE: http://www.quirksmode.org/css/condcom.html
I am creating a simple web application to try out JSF2 with PrimeFaces, so far really impressed by how much it can do out of the box. Going through various tutorials and articles I have a question about properties in templates and whether it is possible to insert these.
I know I can insert chunks of HTML content in templates, for example:
<title>
<ui:insert name="title">Default Title</ui:insert>
</title>
But in some cases it would be useful to insert at property level. The specific one I thought of was TabMenu, where if you were using a TabMenu for navigation (and you want the same TabMenu on every page so it makes sense to use a template), you would want to set the 'activeIndex' differently depending on which page you were looking at. This however does not seem to work in a template file:
<p:tabMenu <ui:insert name="activeIndex">activeIndex="0"</ui:insert>>
<p:menuitem value="Overview" outcome="main" icon="ui-icon-star"/>
<p:menuitem value="Demos" outcome="demos" icon="ui-icon-search" />
<p:menuitem value="Documentation" outcome="docs" icon="ui-icon-document"/>
</p:tabMenu>
Hope that makes sense. Is there a way to do this, or is this design just completely wrong and there is a much better way of doing it?
Pass it as <ui:param>.
E.g. in template client:
<ui:composition template="/WEB-INF/templates/some.xhtml">
<ui:param name="activeIndex" value="0" />
...
</ui:composition>
and in master template:
<p:tabMenu activeIndex="#{activeIndex}">
Does anyone else get this problem or know a solution / workaround I could try as I'm running out of ideas? :-(
I'm running this code on ColdFusion 9 - the idea is that it creates a PDF page (a front cover to a report) applies a watermark (a design I've been given with an orange background that I put my content on) and saves it for use later down the page.
The problem I've got is firstly I needed to turn backgroundvisible on in the cfdocument tag. Reason for this is I kept getting this white square showing on top of my produced page. When I do this though cfdocument then ignore any font colour changes I make it.
I've tried all kinds of combinations of trying to get this including styles, classes. internal / external CSS files but everytime ColdFusion defaults it to black.
Does anyone have any suggestions on what I can do to get this showing in white?
<cfdocument format="pdf" marginbottom="0" marginleft="0.77" marginright="0" margintop="5" pageType="A4" unit="in" name="cover" backgroundvisible="false">
<cfoutput>
<html>
<head>
</head>
<body style="color:##fff">
here
</body>
</html>
</cfoutput>
</cfdocument>
<cfpdf action="addWatermark" copyFrom="#coverFile#" source="cover" foreground="false" opacity="10" showonprint="true" />
<cfpdf action="write" destination='#PDFDir##frontCoverFile#' source="cover" overwrite="true" />
Thanks very much,
James
P.S. It maybe that a workaround has to be using CFIMAGE to produce this and then placing that in the page instead. I'd rather not though :-(
Try using straight HTML styles . Tried it and it seemed to do the job.
Ello world
Unfortunately in the case of this question I had to strip the PDF right back to basics.
I had more problems than just this but generally when it comes to PDF features in ColdFusion Adobe will certainly have to pull their fingers out as it's really buggy :-(
Don't know anything about CF mate, but you have two hashtags before the hex colour, so it probably won't be read!
I have seen in videos, that people get html template by typing "html:5" or something like that (btw, they're not using notepad++). Is this possible in notepad++? Thanks.
A little late, but what you're looking for is called Zen Coding.
The Zen Coding project hosted on Google has a plugin for NotePad++ that should do exactly what you need.
For example, entering something like:
html>head+body>div#content>ul.nav>li*5
Followed by Ctrl + E, expands into:
<html>
<head></head>
<body>
<div id="content">
<ul class="nav">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
Now it's called Emmet plugin in Notepad++
Just type html:5 and press control + alt + enter
and you will get the following markup:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
Option 1
Install and use the Notepad++ Snippets plugin.
You can input whatever code snippet you want and give each snippet a name.
When you double-click on your snippet name, the snippet text just gets copied to your editor (before or after your cursor, based on how you set it)
Option 2
If you don't have admin access or behind a firewall, there is a Macro hack.
If your template is a bit short, then you can use the built-in MACRO and manually key in the template text (a one-time operation per template). You can then "Save Current Recorded Macro" and replay it for every new file that you create. Emmet works only for html, but this technique works for any kind of text(as long as you can manually key-in the text)
Note: You cannot copy-paste (Ctrl-C/Ctrl-V) text while recording as it will copy-paste current clipboard's contents which is undesirable!
For those who like step-by-step instructions:
Open Notepad++. Select Macro -> Start Recording.
Key-in your text (every key-stroke is now being recorded, so minimize backspaces and deletes)
Click : Macro -> Stop Recording
Click : Save Current Recorded Macro and give it a name (say "bash_header" or "html_structure")
Now click on your Macro name to repeatedly apply the template text to your notepad++ file.
Using NP++v6.1.4, I got this to work pretty quickly doing this:
Choose Plugins -> Plugin manager -> Show plugin manager
Wait for all the plugins to be shown, and check the box Emmet
It may alert you that Python will also be installed
Once it completes its installation, allow NP++ to be restarted, and now you can use the many Emmet features :)
Now, just type ! and hit ctrl-alt-enter.
You can use QuickText to create your own templates. It seems that QuickText isn't supported anymore, but it still works, the documentation just has some wrong content.
I use a program called Ditto, it's like a clipboard of all your copy-paste material. I have my prewritten syntax in there pinned. It helps.
In actuality, it is called marking up your code. Although "zen coding" is becoming well known in place of markup, it is the original term for building a structure for your code; which makes it easier for others to read.
As far as the template thing goes for Notepad++, I'm afraid that it is difficult to find public, custom made templates. Although the program does come with custom made templates, such as the Hello Kitty template, your best bet would be to ask people in online programming communities.
My personal favorite is DreamInCode, where they offer help and support, as well as pretty informative tutorials on numerous different computer programming and web development languages. I'm confident that if you can't find one you like that has been posted there, if any, someone would be glad to help you.
Some older browsers are vulnerable to XSS attacks as such
<img src="javascript:alert('yo')" />
Current versions of IE, FF, Chrome are not.
I am curious if any browsers are vulnerable to a similar attack:
<img src="somefile.js" />
or
<iframe src="somefile.js" />
or other similar where somefile.js contains some malicious script.
All major browsers are still vulnerable to these attacks.
Tons of ways of using img tags are still around..
For example...
<img src='#' onerror=alert(1) />
Look for RSnake's xss cheatsheet, those are just some vectors. By the way, I've heard he's coming up with a new version of his cheatsheet soon.
No. Image data is never executed as JavaScript. The if the src is a JavaScript link, the JavaScript is executed, but the fundamental reading of data that comes from a request to the src does not involve JavaScript.
here you can find some XSS attacking vector
http://ha.ckers.org/xss.html