1

I'm building my own blog and I would have lots of articles, so, copying and pasting the head every time, or an aside, the footer or some repeated parts of the blog would be stupid.

So, I'm looking a way to do it in an easy way. I heared about templating (but don't know what it is) and found this answer: Is it possible to create a web site header without copying and pasting it on every page? but it seems that is not what I'm looking for.

I heared about HAML and Markdown (HTML Preprocessors) and don't know if they are used to do what I need.

The solution I want to find is something like @import in Sass.

I have an @import "head.scss"; and in the compiled file I hadn't repeated manualy the (in this case an "imported module" head.scss)


I might say I'm learning to develop my static blog with Jekyll, just because I want to learn to use this technology, and second I know how to use WordPress, Joomla and learning a new thing would be interesting for me but I don't want to learn PHP so I think a templating language will be easier for this project

Community
  • 1
  • 1

5 Answers5

2

If you want to use Jekyll, you can use includes to avoid repeating code.

David Jacquel
  • 51,670
  • 6
  • 121
  • 147
0

The answer is yes it's possible.

In order for a scss file to work you have to make sure the .scss file (or sass file) is converted to css first. (you can look up the many sass tutorials online. for that, just look for converting sass or scss files into css there are even little simple applications for that like scout) By the way, with less you can do the same thing for css files as with sass in terms of importing.

For html files there are templating engines like you said. You can compare popular ones like moustache, dust.js and handlebars just to name a few.

With these you can import snippets of html code inside your file (so you do not have to repeat code).

In programming languages like JavaScript and php you can also do the same thing.

in PHP you can use for example the include() or require() function to import other bits of code from other files into your current file. And in languages like JavaScript you can even use something like angular for example to create simple custom directives to achieve the same goal.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
R.P. da Costa
  • 109
  • 1
  • 15
0

If You are looking easier ways for managing posts and front matter You should look into Jekyll Bash UI or Octopress.

If You want to learn more about Jekyll and its templating system, I'd recommend You to read the Jeyll.tips web page. It contains well formatted and easy to read how-tos, and also covers advanced topics like data files and collections.

Jekyll Bash UI (requires Bash)

Creating a new post is quite easy process, just this on the command line:

jcli.sh new

Octopress

Octopress uses rake utility which makes using Jekyll easier.

For creating a post You just have to call this:

rake new_post["My new post with Octopress"].

After this You can call rake generate to generate the page or rake preview to run the webserver at localhost on port 4000, so You can preview the changes.

-1

Pretty much every server side language I've worked with has shared views in some manner or another.

asp.net webforms has master pages, asp.net mvc has shared views, coldfusion has cfinclude, RoR has partials, PHP has shared layout. I don't know about straight up HTML, but when utilizing a server side language this is definitely possible.

Kritner
  • 13,557
  • 10
  • 46
  • 72
-1

I would suggest using a content management system, like WordPress (https://wordpress.com/) , Joomla (http://www.joomla.org/), or Drupal (https://www.drupal.org/). You create a template one time and load it into the CMS. You can then create as many pages as you need without having copy and paste the template. You can also add in different elements as needed. This makes managing a blog much easier.

If you dead set on doing it one page at a time, I would suggest using PHP to pull in the header. Here is a good article to get you started, Creating a PHP header/footer . However, you'll still need to copy and paste a template file to create a new page.

Community
  • 1
  • 1
Vin Vill
  • 24
  • 5