C++ output with webpages - c++

Is it possible to have a c++ program like this...
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
And have it's output on a webpage like this...
<html>
<head>
<title>C++</title>
</head>
<body>
<div src = "cpp.exe"></div>
</body>
</html>

Not in the HTML per se, no. But if your server supports it (e.g., Apache), you can use a server-side include to execute a program and include the output on the web page.
Your HTML page would look like this:
<html>
<head>
<title>C++</title>
</head>
<body>
<div><!--#exec cmd="cpp.exe" --></div>
</body>
</html>
It isn't a very good approach because there are better ways to produce dynamic content. But if you really, really need to do it this way, that's how...

Not in this way, but you can use C++ as a server side language (pretty much like many others around). This library seems to be interesting: Tntnet. Take a look a this example.

Jeff is right.
You can also use a library like CPPCMS that allow you to do almost the same thing that what you need :
void my_hello_world::main()
{
cout<<"<html>\n"
"<body>\n"
" <h1>Hello World</h1>\n"
"</body>\n"
"</html>\n";
}
Read this tutorial for details : http://art-blog.no-ip.info/wikipp/en/page/tut_hello_world_code
However just make sure that C++ is really what you want to use. As explained in the rationale, the only reason you'd like to use it is in cases you need high performance for your web app.
See : http://art-blog.no-ip.info/wikipp/en/page/rationale

With little modifications to the html, yes, using SSI.

You basically have two possibilities. SSI is built into a number of web servers such as Apache. Alternatively, especially for some older web servers that have less capability built in, or if you want some extra features (e.g., running the program on a separate machine from the web server) you might consider using something like FastCGI.

Related

Rails-like templates in playframework

I'm looking for an alternative to rails templates and yield in playframework, version 2.0.
Is there something similar to that? I couldn't find it by browsing the docs.
I don't know rails but it looks to me like what is explained here for playframework:
http://www.playframework.org/documentation/2.0.1/ScalaTemplateUseCases
#(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>#title</title>
</head>
<body>
<section class="content">#content</section>
</body>
</html>
As mentioned in Somatik's answer Play provides a default template language that is similar to rails' ERB but it is simple enough to replace it with any template engine that you want. You might want to look into Scalate which provides template engines for Mustache and SCAML/Jade (both very similar to HAML).
This discussion on the Play 2.0 Google group points to further documentation on the subject of integrating Scalate into a Play 2.0 application.

CodeIgniter templates

Hello first sorry if its a stupid question, but I amm a beginner, and im a bit lost.
For practice I decided to code a really small social network just for practice.
I worked on small CodeIgniter projects in the past, and the truth is I dont really like loading the header and footer in every controller.
So on YouTube I saw a video about creating basic templating.
But I can't really decide whether it is a good idea.
So how would it look like?
In my view folder I created 3 subfolders
- include
- template
- user
In the templates I have the main_template.php and that looks like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="<?php base_url();?>themes/default/style.css">
<title><?php echo $title; ?></title>
</head>
<body>
</body>
</html>
The controllers would contain different variables for the title and other stuff if needed for each view.
My question is: is it a bad idea not create header and footer files, and creating all views with including the html, head, and body tag like this?
I would recommend using a "header" and "footer". Otherwise it's going to get really messy when you'r trying to customize each template. I get passing down a few variables to the views; actually, that will come in really handy when setting the page's title, meta description, JS/CSS includes, etc. However if you keep your header/footer together, you will have to either pass the entire body in a variable or pass in the name of the specific view you want; in which case you would have to load the specific view inside this main view.
Don't know if I get you right. But, I will put some examples how to use the Template library.
It isn't included, you can take It here : http://gist.github.com/1519385.
Put the Template.php file in /application/libraries.
Make a directory on the views, name It "templates" and inside a "main.php".
This "main.php" file, the name describes it well, let's say that It is your Main template.
Example : http://pastie.org/3071074
There you can see the $content variable, It is defined on your controller.
Example : http://pastie.org/3071097
Thats a very basic example, you can extend It more as you need. Hope It helps.

Import statment in Scala Play Framework doesn't work

I have the following code:
#(data: model.FrontPageData, list:List[model.FrontPageData])(
implicit
params:play.mvc.Scope.Params,
flash:play.mvc.Scope.Flash,
errors:Map[String,play.data.validation.Error]
)
#import controllers._
<html>
<head>
<title>some title</title>
</head>
<body>
....
And Play Framework returns this error:
The file /app/views/Application/frontPageEditor.scala.html could not
be compiled. Error raised is : illegal start of simple expression
on line #↓import controllers._
You can't use import statements from a template in the middle of the code, it's a limitation in Play templates. You must put them at the beginning of the template, as per documentation.
You can use fully qualified names though. In you case, if you have controller XController, do:
controllers.XController.method()
to access it
(Edited after comments)
It is parsing bug on windows systems, based on play framework support response.
On linux systems it works.
Hope they will fix it soon on windows.

Simplest HTML5 template for examples in print

I'm going to be printing out a bunch of HTML5 examples that will be presented in a book format. With this constraint, space is at a premium, so every line I can remove is helpful. I'd like a minimal setup that is clear, but correct, and won't steer anyone down the wrong path.
This is the template I have so far:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<!-- examples... -->
</body>
</html>
I see <meta charset="utf-8"> in every html5 template on the web. Obviously it's best practice to keep it in, but is it so important that I can't remove it, even if it doesn't affect the examples I've provided. Likewise with <!doctype html>.
I could always provide a more robust example in the introduction, but as I expect people to cut-and-paste examples, I'd prefer to have them in a good, but concise, form. Thanks.
You've got to have the DOCTYPE, otherwise HTML5 type stuff won't work in certain browsers (notably IE9). It would probably be safe to leave out the charset - it's not like you can guarantee what charset your readers will be saving the examples in anyway. You will have to add a title element to the head - the document is not valid without it.

Notepad++ premade template

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.