Author |
Message |
Raven
Site Admin/Owner
![](modules/Forums/images/avatars/45030c033f18773153cd2.gif)
Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Thu May 08, 2003 5:43 am |
|
This question has been asked and answered more times than I can recall. There is a PHP built in way to do this that is very simple and fool-proof.
First I will show you an example and then explain it.
Code:
$someVarName = <<<_JSCODE_
<script>alert('Hello World');</script>
_JSCODE_;
echo $someVarName;
|
That's it! You simply insert your JavaScript code as you use it in your HTML document and drop it in. You do not have to escape any quotes or anything special. If it works in native HTML, it should work here.
Now for a caveat. You can use PHP variables in the code WITHOUT using the <? ?> tags. Here would be an example of that.
Code:
$messageText = 'Hello World';
$someVarName = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;
echo $someVarName;
|
Now, if you were using this in a block, you need to assign all content to the $content variable. You could do this in a separate line of code, like this
Code:$messageText = 'Hello World';
$someVarName = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;
$content = $someVarName;
| or just assign the block to $content instead of $someVarName like this.
Code:$messageText = 'Hello World';
$content = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;
|
There is only 1 very important syntactical rule for usage. In my example _JSCODE_ is analogous to a BLOCK TAG. These tags can be named whatever you want, as can the $someVarName. However, the ending block tag MUST be left aligned AND there can be no character EXCEPT a carriage return after either of the block tags.
Note that this is standard PHP code functionality. You can use it anywhere to insert any non PHP code directly into your PHP scripts. |
Last edited by Raven on Thu Oct 09, 2003 8:30 pm; edited 1 time in total |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dragonfly
New Member
![New Member New Member](modules/Forums/images/ranks/1star.gif)
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Aug 31, 2003
Posts: 2
|
Posted:
Sun Aug 31, 2003 7:08 pm |
|
Works good. I used this helpful info to make a collapsing content menu...
There were some questions in the nukecops forums too, but I think I'll post here instead.
Thanks! |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Aug 31, 2003 7:11 pm |
|
Thanks so much! BTW, this method in PHP is called HEREDOC if you want to read up on it. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dragonfly
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Aug 31, 2003 10:52 pm |
|
Raven wrote: | Thanks so much! BTW, this method in PHP is called HEREDOC if you want to read up on it. |
Yeah.. I have not yet read a lot about HEREDOC, but I do have a few books on javascript, cgi, perl, php, asp etc.
I'll look into HEREDOC a little more after I integrate WEFT for IE browsers.. fun stuff - looks like a challenge anyways. If you've heard of anyone using WEFT in phpnuke, please let me know. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
CodyG
Life Cycles Becoming CPU Cycles
![](modules/Forums/images/avatars/186c8977515afcc3ed82a.jpg)
Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island
|
Posted:
Tue Nov 18, 2003 10:26 am |
|
I've been trying to use WHEREDOC in a form and I'm not getting anywhere. It's something like this:
Code:
<?php
// All the opening module stuff
$form_block = "
// then a lot of html form stuff
$content = <<<TERMS
//more html about terms and conditions
TERMS;
//then more form stuff and cases and the submit
";
echo "$form_block";
CloseTable();
include("footer.php");
?>
|
Until now I've been calling this rather long bit of html from the language file as a define.
I'm not having much success with WHEREDOC method in this case. Am I trying to put a variable inside a variable? Can you use WHEREDOC inside a variable? Raven, can you clue me in to how to approach this? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Tue Nov 18, 2003 10:41 am |
|
$form_block is 1 variable and $content is another. From your code I don't understand what you are trying to do - sorry. $content contains your terms so it is just a regular string to php. Use it as you would any other string. You are echoing $form_block but never echoing $content so it will never appear anywhere. TryCode:<?php
// All the opening module stuff
$form_block = " // then a lot of html form stuff ";
$form_block .= <<<TERMS
//more html about terms and conditions
TERMS;
$form_block .= " //then more form stuff and cases and the submit ";
echo $form_block;
CloseTable();
include("footer.php");
?>
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
pure
New Member
![New Member New Member](modules/Forums/images/ranks/1star.gif)
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Jan 07, 2004
Posts: 8
|
Posted:
Wed Jan 07, 2004 11:14 pm |
|
Hi Raven,
Just wondering should I paste all my code here or should I just make a zip file and send it to you. Which ever way let me know and thanks a lot. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 08, 2004 10:02 pm |
|
Normally you can place your javascript code in includes/my_header.php. If you place it w/i the PHP tags, then you must either use the WHEREDOC or echo statments. I recommend the WHEREDOC syntax. Then, you can modify your themes or possibly place the code that calls the javascript in mainfile.php. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
pure
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat Jan 10, 2004 8:51 pm |
|
Hi Raven,
Here's what I am trying to do and the files I am using along with the code.
Basically I want to display a menu created by xara webstyle in a block on left or right side.
I am not a php guru or anything like that I am still trying to learn my way around php. I am having hard time displaying this menu block.
When I created the menu with xara webstyle it creates the following files.
1. SideBar.html
2. sidebar.js
3. xaramenu.js
4. all the .gif files
Here's the path where I have place all these files.
/public_html/pm/modules/SideBar
SideBar.html sidebar.js and xaramenu.js
/public_html/pm/images/blocks
all the images .gif files
Than I created a block-SideBar.php and placed it here
/public_html/pm/blocks
Here's the code in my block-SideBar.php
Code:
<?
include = ("public_html/pm/modules/SideBar/SideBar.html");
?>
|
It did not work did not display the menu.
After reading your thread I created another php file called index.php and upload to
/public_html/pm/modules/SideBar
and now I have 4 files there, SideBar.html, sidemenu.js, xaramenu.js and index.php
My index.php has the following code.
Code:
<?
$content = <<<_JS_
<script src=\"/public_html/pm/modules/SideBar/index.php\"></script>
_JS_;
?>
|
And I changed the code in block-SideBar.php to this
Code:
<?
include = ("public_html/pm/modules/SideBar/index.php");
?>
|
It still did not work. Can you please help me with this? Can you tell me what I am doing wrong and which file I need to place in which folder?
I would really appriciate it. Thank you. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat Jan 10, 2004 10:54 pm |
|
Without looking at the files I can't tell you about those. However, your include syntax is in error. When you include a file you use this type syntaxCode:include("file.html");
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
pure
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat Jan 10, 2004 11:15 pm |
|
Which files do you want to look at? Let me know I will paste them here. Thanks |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
pure
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Tue Jan 13, 2004 1:10 am |
|
No replies yet?
Maybe this is a tuff one. ![Wink](modules/Forums/images/smiles/icon_wink.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Tue Jan 13, 2004 9:15 am |
|
I was waiting to hear if correcting your include syntax helped or not. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
pure
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Tue Jan 13, 2004 2:47 pm |
|
Raven wrote: | I was waiting to hear if correcting your include syntax helped or not. |
Oh ok. Sorry I misunderstood.
Ok when I change the code to point to index.php
Code:
include("/public_html/pm/modules/SideBar/index.php");
|
And try to display the block and hit refresh I get an error "A runtime error has occured. Do you wish to Debug? Line:1 Error: Syntax error"
And I can see the block on the right but empty nothing in it.
If I change the code and point to SideBar.html
Code:
include("/public_html/pm/modules/SideBar/SideBar.html");
|
I still get the same Syntax error but this time the block on the right says
"There isn't content right now for this block."
By The Way here's all the code in the files
block-SideBar.php
Code:
<?php
if (eregi("block-SideBar.php", $_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
include("/public_html/pm/modules/SideBar/index.php");
?>
|
OR
Code:
include("/public_html/pm/modules/SideBar/SideBar.html");
|
index.php
Code:
<?php
if (eregi("index.php", $_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
$content = <<<_JS_
<script src=\"/public_html/pm/modules/SideBar/xaramenu.js\"></script>
<script src=\"/public_html/pm/modules/SideBar/sidebar.js\"></script>
_JS_;
?>
|
SideBar.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SideBar</title>
</head>
<body bgcolor="#ffffff" text="BLACK">
<script src="xaramenu.js"></script><script Webstyle4 src="sidebar.js"></script>
</body></html>
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
pure
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 15, 2004 9:15 pm |
|
Hello!!! ![Rolling Eyes](modules/Forums/images/smiles/icon_rolleyes.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dcasmr
Worker
![Worker Worker](modules/Forums/images/ranks/3stars.gif)
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Feb 06, 2004
Posts: 147
|
Posted:
Sun Feb 20, 2005 5:51 pm |
|
Here we go the second time. I added the proper spaces to avoid some conflicts with my post. Please note that wherever you see added spcaes, it is not due to misspelling.
I have on my site a folder named talkdata. http://www.mysite.com/talkdata. If I open in a normal browser window the attached codes, I get a javas cript link and when I double click on the link, I get the pop-up window.
I am trying to add as module to my Main Menu the link portion so that whenever someone clicks on that module, the pop-up window will open.
Note: the HTML posted must be called from the folder http://www.mysite.com/talkdata.
I have read a few post and even tried creating a module, but with no success.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Musee de Manega - Brendologie</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>
<sc ript language="JavaS cript" type="text/JavaS cript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</sc ript>
<a href="#" onClick="MM_openBrWindow('manegapopup.html','popWimpy','width=450,height=185')">
Musee de Manega</a>
</body>
</html> |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 8:39 pm |
|
You need to set this up as a block or a nuke module called index.php. Then, if you simply echo this code or include it, it will work. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dcasmr
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 10:03 pm |
|
I have tried before creating a module with no luck. Attached are the codes for the module.
1. clicked on, the module does not trigger the pop-up window, but rather opens another window with the link for the pop-up..
2. When I click on the link, nothing happens.
Since the HTML must be opened from a a directory in my nuke site, talkdata, I have used talkdata/manegapopup.html, /talkdata/manegapopup.html with no luck
<?php
#### Generated by Module Creator - By Disipal site (www.disipal.net) ####
if (!eregi("modules.php", $PHP_SELF)) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
//get_lang($module_name);
include("header.php");
$index = 0;
OpenTable();
echo"<p>"
. "<sc ript language=\"JavaS cript\" type=\"text/JavaS cript\">"
. "<!--"
. "function MM_openBrWindow(theURL,winName,features) { //v2.0"
. " window.open(theURL,winName,features);"
. "}"
. "//-->"
. "</sc ript>"
. " <a href=\"#\" onClick=\"MM_openBrWindow('manegapopup.html','popWimpy','width=450,height=185')\">"
. "Musee de Manega</a>";
CloseTable();
include("footer.php");
?> |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 10:18 pm |
|
Why is it a module instead of a block? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dcasmr
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 10:40 pm |
|
A module or a link would be preferable since I want to save space on the main page. Also, I wanted to just add it with my Main Menu.
With a link, I can add it to my site with sommaire parametrable. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 10:41 pm |
|
Then just add it to your blocks/blocks-modules.php file. |
Last edited by Raven on Sun Feb 20, 2005 11:38 pm; edited 1 time in total |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dcasmr
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 10:59 pm |
|
Raven,
I pm you so that you can see what I have as far how it works. Then, if I can re-write the whole thing to the pop-up window as an href link, I could add it to sommaire. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Feb 20, 2005 11:38 pm |
|
Sorry, I meant blocks/blocks-modules.php |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
dcasmr
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Mon Feb 21, 2005 12:53 am |
|
I am totally stuck. When I look at blocks/modules.php I just see PHP codes and do not know how to add the link to it without breaking the codes -
I am very much interested in a solution and will be looking to make a block also. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Raven
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Mon Feb 21, 2005 12:59 am |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|