How to load my own custom Javascript file from the JS folder in Gantry?

2,849 views
Skip to first unread message

Din Muhammad Sumon

unread,
Jan 17, 2012, 5:47:09 AM1/17/12
to Gantry Framework for Joomla Users
How to load my own custom Javascript file from the JS folder in
Gantry? Please
help me.

Luke Douglas

unread,
Jan 17, 2012, 12:09:56 PM1/17/12
to Gantry Framework for Joomla Users
Din Muhammad Sumon,

I'm assuming you have a JavaScript function you want to add for use on
your website so here goes.

First, upload your JavaScript file to the 'templates\rt_gantry\js'
folder.

Open up the default Gantry template index.php file and look for this
line in the '<head>' section but with different filename other than
'customsscript.js'.

$gantry->addScript("customscript.js");

If you find it, add your script like this changing the
'customscript2.js' to the name of your JavaScript file.

$gantry->addScript(array('customscript.js', 'customscript2.js'));

Save the file.

However, if you don't find that line, then look for the line like
this:

$gantry-
>addStyles(array('template.css','joomla.css','style.css'));

Add this line below it and change 'customscript.js' to the name of
your custom script.

$gantry->addScript("customscript.js");

Save the file.

This should dynamically include your JavaScript file when the site is
loaded.

Luke

Luke Douglas

unread,
Feb 19, 2012, 10:12:09 AM2/19/12
to Gantry Framework for Joomla Users
Din Muhammad Sumon,

Actually, I have found the proper way to do this using the
mycustomstyle routine.

Modify the mycustomstyle.php file by adding the 'addScript' function
below the 'addStyle' function. Like this:

<?php
/*
* @package Custom Feature (Add custum stylesheet) - RocketTheme
* @version August 1, 2010
* @author RocketTheme http://www.rockettheme.com
* @copyright Copyright (C) 2007 - 2010 RocketTheme, LLC
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
*
*
*/

defined('JPATH_BASE') or die();

gantry_import('core.gantryfeature');

class GantryFeatureMyCustomStyle extends GantryFeature {
var $_feature_name = 'mycustomstyle';

function isEnabled() {
return true;
}

function isInPosition($position) {
return false;
}

function init() {
global $gantry;

//custsom CSS styles & JS functions
$gantry->addStyle("mycustomstyle.css");
$gantry->addScript("https://ajax.googleapis.com/ajax/libs/jquery/
1.5.1/jquery.min.js");
}
}
?>

This will allow you to include JS script files without touching the
Gantry files at all. Much better.

Luke

On Jan 17, 11:09 am, Luke Douglas <l...@webbering.com> wrote:
> Din Muhammad Sumon,
>
> I'm assuming you have aJavaScriptfunction you want to add for use on
> your website so here goes.
>
> First, upload yourJavaScriptfile to the 'templates\rt_gantry\js'
> folder.
>
> Open up the default Gantry template index.php file and look for this
> line in the '<head>' section but with different filename other than
> 'customsscript.js'.
>
> $gantry->addScript("customscript.js");
>
> If you find it, add your script like this changing the
> 'customscript2.js' to the name of yourJavaScriptfile.
>
> $gantry->addScript(array('customscript.js', 'customscript2.js'));
>
> Save the file.
>
> However, if you don't find that line, then look for the line like
> this:
>
>             $gantry-
>
> >addStyles(array('template.css','joomla.css','style.css'));
>
> Add this line below it and change 'customscript.js' to the name of
> yourcustomscript.
>
> $gantry->addScript("customscript.js");
>
> Save the file.
>
> This should dynamically include yourJavaScriptfile when the site is
> loaded.
>
> Luke
>
> On Jan 17, 4:47 am, Din Muhammad Sumon <dmsu...@gmail.com> wrote:
>
>
>
>
>
>
>
> > How to load my owncustomJavascriptfile from the JS folder in
> > Gantry? Please
> > help me.

Din Muhammad Sumon

unread,
Feb 19, 2012, 4:44:56 PM2/19/12
to gantry-framework...@googlegroups.com
Thanks a loooot Luke Douglas. Your previous technique also worked for me and was very helpful and the new tips has increased my knowledge about Gantry! Thanks a lot ....

> > Gantry? Please
> > help me.

--
You received this message because you are subscribed to the Google
Groups "Gantry Framework for Joomla Users" group.
To post to this group, send email to
gantry-framework...@googlegroups.com
To unsubscribe from this group, send email to
gantry-framework-for-j...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/gantry-framework-for-joomla-users?hl=en

Gantry Framework Homepage: http://www.gantry-framework.org



--
Din Muhammad Sumon

Din Muhammad Sumon

unread,
Feb 19, 2012, 4:48:54 PM2/19/12
to gantry-framework...@googlegroups.com
I have a QS where shall I find this mycustomstyle.php file? Or shall I have to make this file in any folder? But in which folder? Plz provide me details. Thank you
--
Din Muhammad Sumon

Luke Douglas

unread,
Feb 20, 2012, 12:26:51 AM2/20/12
to Gantry Framework for Joomla Users
Din Muhammad Sumon,

This tutorial will walk you right though it.

http://www.rockettheme.com/forum/index.php?f=337&t=106162&rb_v=viewtopic

Remember, in the mycustomstyle.php file, you can add the ' $gantry-
>addScript("customscript.js"); ' right below the addStyle line and
then put your JS file into the 'js' directory. You do not need to put
any folders as it will automatically pick up the JS file form the 'js'
directory.

Luke


On Jan 17, 4:47 am, Din Muhammad Sumon <dmsu...@gmail.com> wrote:

David Gordon

unread,
Aug 6, 2014, 11:07:31 PM8/6/14
to gantry-framework...@googlegroups.com
Hi Luke,
Many thanks for sharing this info.  I have another question.  I am actauuly being asked to add into the header section of my index.php the following;

<script data-main="mintcodesytvc/js/app/main" src="mintcodesytvc/js/app/require.js"></script>

Can you explain how to include the data-main="mintcodesytvc/js/app/main" element of the command using $gantry->addScript?

Regards
Dave
Reply all
Reply to author
Forward
0 new messages