How to create global variables to share between HTML pages - html

Hi I am currently working on porting over an application to a new server and I each time I move the application to a new directory I have to manually go in and change all of the img, src, and script tags within the html pages. This is becoming very tedious because there are over 30 different pages.
Is the anyway to create a configuration file that holds global variables that can then be included at the top of every HTML file? For example, if I change the path to a script, the only change I would have to make is in the configuration file and not every separate html file.
edit to clarify:
Currently I have hard coded scipt/img/scr tags that look like this:
<link rel="stylesheet" type="text/css" href="/app/returning/html/returning.css" />
I was hoping I could make the href value a variable in a separate file that can be included at the top of every page and it would look something like this:
<link rel="stylesheet" type="text/css" href="(variable from configuration file here)" />

You can create another javascript file with an object with all settings/configurations, and include it in every HTML page.
Something like:
var settings = {
applicationName : "TEST",
IsInDebug : true
};

Related

How to include .htm file in .htm file (html)

i have 3 files:
a.htm
main page
b.htm
includes CSS or JS code
c.htm
includes a table
how can i import b.htm & c.htm into a.htm so that i could use the view the table and use the CSS or JS?
the idea is to use the same layout on multiple layouts.
If you want to code properly I think that you've two options.
The first one is ìf you don't want to use a server-side language:
CSS : <link rel="stylesheet" type="text/css" href="style.css">
JS : <script type="text/javascript">
HTML : Just put your table into the main html (the one where you want to include this file) If your table is not fed by Datas using PHP/SQL I don't think that would be relevant to seperate it.
The other option is to use PHP so you can include views in your code. And if you want to go further and create/use some interesting fonctions you should do it using MVC.

404 from CSS file

Is there any reason why I'd be getting a 404 error from a CSS file with a version number on the end of it?
<link rel="stylesheet" href="styles/main.css?v=123">
My file is also named main.css?v=123.
Any help is appreciated. Thanks in advance!
You should rename your file to just main.css, then in the html reference it like this: <link rel="stylesheet" href="styles/main.css?v=123">
You'll only need to change the version in the HTML after you've updated your css. Remember, your css file will always be named just main.css
Hope that helps!
Just to clarify this is called querystring caching. You add the querystring in the HTML only. When you change it most browsers will assume it's a new file and reload it regardless of how you set the cache for CSS files.
It's possible to do this via PHP without having to manually change it every time you change the css file.
<link rel="stylesheet" href="styles/main.css?t=<?php echo filemtime( 'styles/main.css'); ?>" type="text/css" media="screen" />
This appends the css files modification time to the HTML. Every time you save the CSS file this will update automatically.
By this type of link, you passed to browser the HTTP request GET, with argument v and its value 123. Server is still looking for main.css. The 404 code means page not found.
If you want to server handles it use URL-rewriting.
Or you can try encode the question mark by typing %3F.
Please note that file names containing question marks aren't allowed on windows and MSDOS systems.

Generating a pdf-file out of a twig template

I want to generate a pdf (an invoice as letter) out of a twig template. The template uses a css and contains a header with a logo (png-image) and a footer, which should appear at the bottom of the document.
I tried it with the KnpSnappyBundle, but this doesn't work (css only works inline, images are not rendered..., etc.). Are there any other tools to generate a pdf?
With Java I used jasper-reports (really cool), isn't there anything similar for php?
I have used KnpSnappyBundle to generate pdf before, and it worked with external css files, thought there's is some diffrence bettween regular tempaltes:
When linking asset you have to provide absolute path:
<link type="text/css" rel="stylesheet" href="{{ asset('css/css.css', null, true) }}" />
I didn't needed images files, but I think it should work the same, also you need to use "renderView" method instead of "render".
$pdf = $this->renderView('**:**:tempalte.html.twig', array());
After that you just simple use:
$file = $this->container->get('knp_snappy.pdf')->getOutputFromHtml(pdf);
The answer is: The server startet via
php app/console server:run
is single-threaded, so there is no chance, to get a response, when requesting an image or css-file...

can't locate css files in paths

My directory structure is something like this
APPLICATION
|
+-[code]
+-[config]
+-[database]
+-[includes]
+-[src]
+-.htaccess
+-composer.json
Pretty self explanatory. The .htaccess guides requests to src/index.php, the code is the middle tier logic, the database is the DAL and the config is configuration INI filies.
The problem I have is that my header file... I have a header.php file in [includes] that holds all of my css directives (html5reset, global.css, etc) but for some reason I can't access them. The fact that I can access the header file makes me think I should be able to access the css files (which live in [includes]) but they are not loading.
The odd thing is, in firebug, it looks like the actual html page is loading in the place where the css is loading.
this is my call from /includes/header.php
<link href="/includes/css/html5reset.css" type="text/css">
Confusing question, I apologize. Any advise would be appreciated.
in your config.php file you can define a URL (baseurl)
define('URL', 'http://localhost/myproject/');
then you could use this defined variable like so...
<link href="<?php echo URL ?>includes/css/html5reset.css" type="text/css">

Applying different Cascade Style Sheets to the same html page

To apply a CSS to an existing html page I need to add a link that links to the css file, I am asked to include a link in the webpage that I am building that would link to the same html page but with a different css file, I am thinking I need to create a different css file, then create another .html page by copy the exact content from the first page and only change the link of the css file, but it doesn't seem so efficient and I am assuming there should be a standard method to do this.
thanks
you can use a JAVAscript to documet.write a link
If you can use a server-side language like PHP, I would do it something like this:
<?php
$allowed_stylesheets = array("red", "white", "blue", "green", "mobile");
$default_stylesheet = "red";
$stylesheet =
(in_array($_GET["stylesheet"]) ? $_GET["stylesheet"] : $default_stylesheet);
?>
<link rel="stylesheet" type="text/css" href="<?php echo $stylesheet; ?>">
you would then be able to call your page, and switch the style sheet like so:
www.example.com/page.php?stylesheet=mobile
note that to make a .html page run in PHP, there is probably some server setup necessary, by default only .php pages are parsed in PHP. Depending on your situation, that may be too much hassle than it's worth. However, I don't know any pure HTML way of switching style sheets reliably.
Also, this way, you will have to repeat the style sheet command every time you call the page.