I would like to have a "Recent Activity" stream on the left side of my index.html file. I have the following code:
<div id="sidebar">
<div class="box1">
<div class="title">
<h2>Recent</h2>
</div>
<ul class="style2">
<li>27 Aug - Conference Meeting</li>
<li>26 Aug - Website Created</li>
</ul>
</div>
</div>
And basically I'd like to be able to store the contents (the activities) in a seperate file, so that I can import that file into the various pages across my website.
I'm very new to CSS and webdesign and I've tried to find the answer on google, but haven't run into any luck. I've been tasked with creating a website for my team's college project.
Thanks for the help in advance.
In order to do this, you can use CSS like this:
.box1{content: url(http://www.example.com/test.html)}
see more at Mozilla Dev
This being said, I highly advise NOT to do it this way. This is NOT what CSS is intended for. You better use some kind of include like Server Side or PHP. If you don't know coding, you can always use a CMS like WordPress which will make this kind of task a breeze
You can use Javascript (or some library of same) to read in the file w/ the activities (or, if represented using javascript, could just import that file) and then use javascript to insert the activities into the appropriate part of the DOM.
The solution is not stripping out html from an existing file but to build up your html files from different sources using a server sided script language like php.
With php you would have just one page (for example index.php) and include the content the user requests (like home, contact, guestbook, whatever).
The proper way would be to use a database for storing the information but this is far too difficult for begining with web development.
Save the html for the sidebar to a separate html file (sidebar.html). Rename your index.html to index.php.
Go to the location in index.php where your html code for the sidebar is and delete it and instead just insert this:
<?php include "sidebar.html"; ?>
This code includes your html file inside your index.php and your can reuse it on different pages by just including the same sidebar.html on every page where you need it.
The benefit is to be able to modify it in just one file if you need to make changes.
Now here is the disadvantage in this solution: You need php installed on the server your website will be hostet. Php is a program which interacts with the webserver and everytime a .php file is requested by a browser it will be handed over to php first for parsing the file and doing the includes, database access and many other cool things. So in order to use php-files and include html files within other html files you need php installed on your webserver. Also if you open your .html file by double clicking you won't be able to see the complete result unless you have a local webserver with php installed on your computer. That's all free software (apache2 and php) but for a beginner it's not so easy to install it. Maybe start with a prebuild package like xampp. (This contains the webserver and php with preconfigured settings to start quickly).
This topic is pretty basic for php so you will be able to find lots of tutorials on the internet about getting started with php. Good luck and have fun. ;)
In simple words, you can do it with <iframe> tag or with the css Content property but it won't give you possibilities as what JavaScript or PHP can give you.
To do it with JavaScript you can view this question .
Thank you everyone for your help and assistance. This has been a learning experience. For anyone who has the same issue, here is the solution that I've found using some help from the members who kindly responded to my question.
Here is my css:
<div id="sidebar">
<div class="box1">
<div class="title">
<h2>Recent</h2>
</div>
<script type="text/javascript" src="js/recent.js"> </script>
</div>
<div class="box2">
<div class="title">
<h2>Relevant Links</h2>
</div>
<script type="text/javascript" src="js/links.js"> </script>
</div>
</div>
And here are my two *.js files:
// recent.js - Create recent activity feed
document.write("<ul class=\"style2\">");
document.write("<li>29 Aug - 10 Photos Added</li>");
document.write("<li>28 Aug - Meeting Page Added</li>");
document.write("<li>27 Aug - Meeting</li>");
document.write("<li>26 Aug - Website Created</li>");
document.write("</ul>");
// links.js - Create list of links
document.write("<ul class=\"style2\">");
document.write("<li>Formula SAEĀ®</li>");
document.write("<li>SAE International</li>");
document.write("</ul>");
It may not be the prettiest way to do it, but it seems to work. The problem with the iframes was that if I clicked on a link, it opened it within the iframe. Thanks again everyone! I knew nothing about javascript, css, and it's been a learning experience! :)
Related
For my school I have to work 1 month in a company. I'm making a website and one of the requirements is that I only make 1 Navigation that I use on every HTML page.
Obviously I want to do it myself without asking the company to help me, but after looking an hour i didn't really find a good solution.
I rode some stuff about php, but whenever I add it in my HTML it doesn't do anything. Someone that could help me?
One Nav HTML Page for all my HTML Pages so when I edit 1 thing it changes for every HTML Page.
you could maybe get it working with <iframe> i believe i used that back in the day for a site (code was so dirty looking)
I would recommend using php, your directory would look like this
map
|-index.php
|-nav.php
Inside the index.php you want to use include
index.php
<html>
<body>
<?php include 'nav.php'; ?>
<h1>super awesome site</h1>
</body
</html>
nav.php
<nav>
my nav bar
</nav>
Now because you are using php you can't just open the file in your web browser, you will need to run a web server directed to this file or use php -S localhost:8080 to start a local test server in the current directory
if you have any questions don't hesitate to ask
edit: put nav.php in qoutes
You can use PHP
<?php
include 'nav.php';
//body
?>
Get Started with PHP: http://php.net/manual/en/tutorial.php
Install PHP: https://www.cloudways.com/blog/how-to-start-php-programming/
Well you can do you custom nav in a separated HTML file and attached it to every page of your website and for the PHP to work
your file should be .php file and placed on a server which is created to run php files such as Apache server.
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
as you see here the footer is seprated HTML file which u can use at every page of your project :).
Currently, I am trying to use Codepen Project's environment to build a website and later deploy it. I am using a template that I want to start building from. It has its own HTML pages as well as CSS and JS that is linked. However, when I am working in the project environment I cannot seem to get the CSS to apply to the html code (in other words, the live preview keeps showing naked HTML). I have tried uploading the files into the project's root, tried copying them in newly created css files, and tried using them as external sources (href to an external url in the head tag).
It is really to bad because I feel the Project environment can really offer a lot, though I just can't get it to work.
Thanks in advance, and take care!
LINK TO CODEPEN PROJECT:
https://codepen.io/Thumpertje/project/editor/DxxkqM/
<div class="code">
</div>
Every time I decide to change something in my header/navigationbar/footer/etc. I need to apply those changes to 16 other html files so my changes are consistent across my entire website.
My question is: is there a way i can make my website's template be automatically applied to every page?
An example of any page on my website and what i have in mind would look like this:
<html>
<head>injected code</head>
<body>
<header>injected code<header>
<section>NOT INJECTED CODE</section>
<footer>injected code</footer>
</body>
</html>
I know repeating code like this is bad practice, so how do i reuse (localize) code for these areas of my html since they will always be the same?
I am not really interested in content management systems.
What i do with the elements that are the same on every page, like the header, nav, footer is create those elements in a file apart and then include via php. Then if you have to change one thing in the header you only have to do it one time.
Your example will be like:
<body>
<header><?php include_once('header.html'); ?><header>
<section>NOT INJECTED CODE</section>
<footer><?php include_once('footer.html'); ?></footer>
</body>
Hope it helps.
You can use php to solve this. Name your file "index.php" (or anything else with .php as the extension)
<html>
<?php include('header.php'); ?>
<body>
<header>injected code<header>
<section>NOT INJECTED CODE</section>
<footer>injected code</footer>
</body>
<?php include('footer.php'); ?>
Then make header.php and footer.php in the same folder. These common files can then be included in all your pages.
Tip: You will need to run these on a local server. See xampp
The best way that I can think of would be to use a server side language, such as php or asp , to generate the html.
You can use <iframe> tag to include external file however I have not properly tried this and am not sure of the security or results.
You can also use javascript/jquery to write to the document, however using scripts just to write would not be best practice, a better use for client-side language would be to use ajax to load external files however some of the header may need to be defined before the ajax is complete although I haven't tested it.
In short I would recommend using a server side language probably php as it is easy to learn, free to use and you can install it on your local machine. If you already have a server running you can see what languages are already installed as most languages can include external files.
I have pretty much no experience with HTML, but I am using Doxygen to create code documentation. I have all the Doxygen generated HTML files in a sub-directory within my C project.
This documentation is for a library I have built and I would like the user to be able to view the HTML documentation without having to search through the Doxygen sub-directory for index.html. I tried to make a Windows shortcut to index.html, but that only works on my working computer. Whenever I try on another computer, Windows requests the username and password of my working computer. Then I tried copying the index.html file to the top-level of my library; however, in doing so, it seems like many links were broken and the file did not open properly.
Please note that I am not looking to host this documentation on a server, the documentation will be distributed with the source code, since this library is (currently) for internal, educational university use and I am not sure if I am allowed to make it open-source.
In other words, this is the type of file structure I'm looking for:
Project Folder
-Doxygen Documentation Folder
-index.html
-Source Code Folder
-Shortcut to index.html
There's a thread here that should help.
Essentially the suggestion is to have a top-level index.html that links or redirects the reader to the one in the doxygen folder. I note you're new to HTML but it's quite simple.
There's an example of a minimal index.html you could use towards the bottom of that thread which I'll replicate here in case that thread ever disappears. It was contributed by Clemens Feige.
<head>
<meta http-equiv="refresh" content="1; URL=doxygen/index.html">
</head>
<body>
<p>You will be redirected automatically, otherwise please click here.</p>
</body>
You'll need to tweak the paths according to your set-up.
I ended up using this software But I think I like Cheeseminer's solution better
I am learning Symfony2, and I am making small tests.
Well I have made a small html for to test the twig templates.
<html>
<head>
<title>test00</title>
<link rel="stylesheet" href="test.css" />
</head>
<body>
<div id="test">
<img src="test.png" /><br />
test
</div>
</body>
And the files are in the same directory of html.
Then copy all files (html, css and the images) to my test:
/var/www/Symfony/src/Test/TestBundle/Resources/views/Default
And rename the html to html.twig.
But fail when use this html as twig template, because the Symphony try to use "http://localhost/Symfony/web/test.png" as link the image.
And yes, I have read the documentation and know the "asset" and I can change the path to the files with some example
test.png')" /> and also copy all files to the web directory in the budle.
But I wonder "Is there any tool to convert html to twig?" because for example I can't say to my boss:
"The Symfony2 is great. But your designer must to learn Twig and when she finish the html with dreamweaver, she must change all of links to css and images for to make a template...and yes she can't see anything only can send to me to put in the web server to check if it is correct."
What do you hope that my boss will think about Symfony2? He will think this is crazy, this is twice of work.
I think the best it is a automatic tool to translate a html with relative paths to twig and something like that a package files to put in web dir. And the designer does'nt need to know anything only make pretty htmls with few weird things as put {{page_name}} instead the "Page name".
Regards.
From an html coders perspective, Twig is HTML. As long as templating language support is setup on your server, there is no difference between writing twig or HTML. The only difference would be the <h1>{{variables}}<\h1>. Your HTML coders should be aware of what variables they have access to. That being said, from a developers perspective, twig is a lot more so I'm not simplifying twig. But if someone knows HTML, they'll know what to do with twig.
Then copy all files (html, css and the images) to my test:
/var/www/Symfony/src/Test/TestBundle/Resources/views/Default And rename the html to html.twig.
Nope. Your html.twig files need to end up somewhere under views so the template processor can get to them. However, your css and images need to be copied to your root web directory. Same place where app.php lives.
But fail when use this html as twig template, because the Symphony try to use
"http://localhost/Symfony/web/test.png" as link the image.
It's is not symfony generating this link but your web browser. Use Control-U to examine the generated html source from within your browser. You will find that your links such as href="test.css" have not been changed. Twig will not change anything unless it has has some curly brackets around it.
So your designer can continue to use her current workflow and deliver a set of files. You just need to deploy the files to the correct locations.
Of course symfony/twig can do a lot more that simple variable replacements so eventually you might want to change things. But you can get started just fine.