Questions tagged [include]

A provision that many programming languages provide to allow functionality defined in one file to be used in another.

include is a provision that many programming languages provide to allow functionality (code such as functions, classes, objects etc.) in one file or package to be referenced and used in another.

Example (PHP)

include './dir/file.php';

Resources

9740 questions
253
votes
15 answers

How to include() all PHP files from a directory?

In PHP can I include a directory of scripts? i.e. Instead of: include('classes/Class1.php'); include('classes/Class2.php'); is there something like: include('classes/*'); Couldn't seem to find a good way of including a collection of about 10…
occhiso
  • 3,161
  • 4
  • 22
  • 16
238
votes
2 answers

ASP.NET MVC 3 Razor: Include JavaScript file in the head tag

I'm trying to figure out the proper Razor syntax to get a JavaScript file for a particular *.cshtml to be in the head tag along with all the other include files that are defined in _Layout.cshtml.
Stephen Patten
  • 6,333
  • 10
  • 50
  • 84
235
votes
2 answers

How to include another XHTML in XHTML using JSF 2.0 Facelets?

What is the most correct way to include another XHTML page in an XHTML page? I have been trying different ways, none of them are working.
Ikthiander
  • 3,917
  • 8
  • 37
  • 54
226
votes
4 answers

Creating your own header file in C

Can anyone explain how to create a header file in C with a simple example from beginning to end.
Anuragdeb3
  • 2,299
  • 3
  • 14
  • 4
207
votes
10 answers

Can we call the function written in one JavaScript in another JS file?

Can we call the function written in one JS file in another JS file? Can anyone help me how to call the function from another JS file?
Hemant Kumar
  • 4,593
  • 9
  • 56
  • 95
193
votes
29 answers

Dynamically load a JavaScript file

How can you reliably and dynamically load a JavaScript file? This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand. The client that uses…
Adam
  • 28,537
  • 15
  • 60
  • 73
192
votes
10 answers

Displaying the #include hierarchy for a C++ file in Visual Studio

Problem: I have a large Visual C++ project that I'm trying to migrate to Visual Studio 2010. It's a huge mix of stuff from various sources and of various ages. I'm getting problems because something is including both winsock.h and…
RichieHindle
  • 272,464
  • 47
  • 358
  • 399
185
votes
4 answers

How to add include path in Qt Creator?

I have a project I'm working on in Qt creator that requires a third-party library. I want to add the headers to the include path for the project. How do I do this?
Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
183
votes
33 answers

Prevent direct access to a php include file

I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included. Basically I need to do a check as…
Alterlife
  • 6,557
  • 7
  • 36
  • 49
178
votes
6 answers

How to including variables within strings?

So, we all should know that you can include variables into strings by doing: String string = "A string " + aVariable; Is there a way to do it like: String string = "A string {aVariable}"; In other words: Without having to close the quotation marks…
Gray Adams
  • 3,927
  • 8
  • 32
  • 39
176
votes
7 answers

Difference between "include" and "require" in php

Is there any difference between them? Is using them a matter of preference? Does using one over the other produce any advantages? Which is better for security?
Dan Hanly
  • 7,829
  • 13
  • 73
  • 134
172
votes
5 answers

How to include file in a bash shell script

Is there a way to include another shell script in a shell script to be able to access its functions? Like how in PHP you can use the include directive with other PHP files in order to run the functions that are contained within simply by calling the…
Anthony Miller
  • 15,101
  • 28
  • 69
  • 98
171
votes
10 answers

How does the keyword "use" work in PHP and can I import classes with it?

I have a file with a class Resp. The path is: C:\xampp\htdocs\One\Classes\Resp.php And I have an index.php file in this directory: C:\xampp\htdocs\Two\Http\index.php In this index.php file I want to instantiate a class Resp. $a = new Resp(); I…
Green
  • 28,742
  • 61
  • 158
  • 247
165
votes
22 answers

"#include" a text file in a C program as a char[]

Is there a way to include an entire text file as a string in a C program at compile-time? something like: file.txt: This is a little text file main.c: #include int main(void) { #blackmagicinclude("file.txt", content) /* equiv:…
ZeD
160
votes
5 answers

What's the difference between including files with JSP include directive, JSP include action and using JSP Tag Files?

It seems that there are two methods for templating with JSP. Including files with one of these statements <%@ include file="foo.html" %> or using JSP tag files // Save this as mytag.tag <%@ tag…
sonicboom
  • 4,928
  • 10
  • 42
  • 60