File templates in KDE Dolphin

You know that you can have a  “New file” menu on Right click in Dolphin. One of these is an HTML file. It can be customized heavily as it is just a template.

The original file resides here:

/usr/share/templates/.source/HTMLFile.html

The content of the file shows that this is the copied template:

[[email protected] ~]$ cat /usr/share/templates/.source/HTMLFile.html 
<html>
  <head>
    <title></title>
    <meta content="">
    <style></style>
  </head>
  <body></body>
</html>

For details about the key value specification of the desktop file, look here.

 

Creating a new File type:

Create a template. I’ll use the following for XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                                                                                         
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">                                                                                   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">                                                                                    
<head>                                                                                                                                                 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>                                                                           
        <title></title>                                                                                                                                
</head>                                                                                                                                                
<body>                                                                                                                                                 
</body>                                                                                                                                                
</html>

Save it as /usr/share/templates/.source/XHTMLFile.xhtml

Now create the .desktop file which controls the menu appearance at /usr/share/templates/XHTMLFile.desktop

[Desktop Entry]
Name=XHTML File
Type=Link
URL=.source/XHTMLFile.xhtml
Icon=text-html

That’s it. On closing and reloading Dolphin, you will get a new menu item on Create.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.