I need to include in my joomla project some external libraries but I don't understand how to do this.
However, I find that is necessary create a directory com_mycomponent and inside enter all files/folders js and css.
Ok, I do this but.. where I should tell joomla where they are?... I know that is necessary insert this lines:
JHtml::_('script', com_myComponent/js/file.js', false, true);
JHtml::_('stylesheet', 'com_myComponent/css/file.css', false, true);
but where I need to insert them?
Thank you so much
Joomla is very friendly Framework, Very simple to add external libraries
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" >
$document = JFactory::getDocument();
$document->addStyleSheet('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css');
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
$document->addScript('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js');
Read the Docs https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page
Related
I am trying to include a custom JS file into my joomla site. What I did is to edit the template's index.php file, and add <script src='custom.js"></script> right before </head>. But when the page is loaded, there are two other JS files loaded after my custom JS file. I thought by inserting my script loading line right before the closing head tag, my JS file should be the last one to load. What could possibly load those 2 JS files after my JS file, and how?
Try this,
you can use addCustomTag option this will not load the JS file inside your head tag but it should be last (from where you are calling there it load.)
$stylelink .= '<link rel="stylesheet" href="../css/IEonly.css" />';
$document = JFactory::getDocument();
$document->addCustomTag($stylelink);
For more details
Hope it works..
There is an option to specify execution of the script after page has loaded (defer). This is a HTML feature and addScript() exposes this in its interface. Doc: https://docs.joomla.org/JDocument/addScript
Example:
$document = JFactory::getDocument();
$document->addScript('js/myscript.js', 'text/javascript', true);
In my custom Joomla 3 extension I am using Bootstrap 2.3.2 for the front-end. I noticed that the default Joomla template protostar overwrites default Bootstrap classes which is not what I would like. Is there a way to load my stylesheet after the template's stylesheets so they overwrite any common rules may exist?
Try something like this,
This will add the css at your component calling time inside the component HTML section . Keep in mind it will not add the css at head section but for sure it will appear after the template css
$stylelink = '<link rel="stylesheet" href="../css/css.css" />';
$document = JFactory::getDocument();
$document->addCustomTag($stylelink);
Hope it works..
I am using asp.net mvc3. I have two script files on my web site like these:
<script type="text/jscript" src="/SiteName/lib/jquery/menus.js"></script>
<script type="text/jscript" src="/SiteName/lib/jquery/dialogs.js"></script>
These are real paths for these two .js files where the SiteName directory is on the root of my website.
Now when the site rendered, i want to be these pathes like:
<script type="text/jscript" src="/lib/jquery/menus.js"></script>
<script type="text/jscript" src="/lib/jquery/dialogs.js"></script>
As a result, the "SiteName" portion is deleted from the path! but really it is available!
Yet the browser must be able to load these scripts.
I think this must be done by routes.MapRoute or like these!
You can use BundleConfig to achieve this. You can create styles and script bundles that have a virtual path with the added benefit of minification. If you add multiple scripts into one bundle, it'll join and minify both into one virtual script. e.g.:
bundles.Add(new ScriptBundle("~/lib/jquery").Include(
"~/SiteName/lib/jquery/menus.js",
"~/SiteName/lib/jquery/dialogs.js"));
On page render, it'll show up as:
<script type="text/javascript" src="~/lib/jquery"></script>
From memory this wasn't there by default in MVC3, but it looks pretty easy to implement if you refer to this answer: https://stackoverflow.com/a/12754108/769083
Actually my question is How is folder path hidden ? Firstly I am using Joomla.
I found a website 4 months ago, so i don't remember name of the website which is Joomla site. They hide their folder path.
Between to head> sth. head(tags). If you look at source code, you can see this part. And then this part include template name.
For example:
<link type="text/css" href="http://www.site.com/templates/template_name/css/style.css" rel="stylesheet"></link>
So we can learn to what the name of the template. But they hide this part. When i looked this part(http://www.site.com/templates/template_name/css), i can see only /style.css.
Do you have any idea?
You need two things to accomplish that.
A (system) plugin, that changes every template related URL to the 'official' format, eg.
$url = str_replace('/templates/template_name/css/', '/style/', $url;
An .htaccess redirect reverting the change.
RewriteRule ^style/(.*)$ templates/template_name/css/$1 [R=301,L]
If you want obscure template names, and a few modules and plugins from HTML source, the easy way is use a CSS and JS compressor like jbetolo or RokBooster.
But keep in mind that you will make a bit more hader to find your template name, but still possible via other ways. Like some images if they are not compressed in HTML.
Is it possible for a single page on a Joomla website to include it's own custom .js and .css files?
I basically would like to add two custom javascript and css files for a particular page. I don't want these files included into any other Joomla pages.
Any suggestions would be appreciated.
Thank you
Try using a custom code extension such as JUMI. It is designed exactly for this purpose.
From the description: With Jumi you can include php, html, javascript scripts into the modules position, articles, category or section descriptions, or into your own custom made component pages.
The solution from Soygul wont result in proper HTML since these statements / includes belong to the HTML header.
Use : http://extensions.joomla.org/extensions/edition/custom-code-in-modules/11936
This plugin allows inserting material into the head section of your Joomla web site.
You can then use the menu assignment functionality to just add that to certain pages.
Its quite easy to write a simple module like that for yourself - but since this seems already available go with that one. If it doesn't fit your needs :
You just need an "empty / hello world" module with these two statements :
( http://docs.joomla.org/Creating_a_Hello_World_Module_for_Joomla_1.5 )
( http://docs.joomla.org/Adding_JavaScript_and_CSS_to_the_page )
// Add a reference to a Javascript file
// The default path is 'media/system/js/'
JHTML::script($filename, $path, $mootools);
// Add a reference to a CSS file
// The default path is 'media/system/css/'
JHTML::stylesheet($filename, $path);
I'm not a big fan of adding new extensions to Joomla unless absolutely necessary. If you do, make sure it's not on Joomla's list of vulnerable extensions, first. Each third-party extension/plugin you add is just one more potential back door for hackers.
To add your own custom CSS for a page, you can either edit your template's master CSS file, or just create your own and link it to the project. Here's how you'd do that:
First, figure out how your CSS files are being called. The actual file names will surely differ from my example, based upon the template you're using, but let's look at the Joomla SYSTEM template, which is located in templates/system. The index.php file controls everything, so open it up and you'll find this line:
<?php
include dirname(__FILE__).DIRECTORY_SEPARATOR.'component.php';
?>
Open component.php and you'll see some code that looks like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
You can see the call to include a CSS file in the 3rd line. All you need to do is add another line calling a CSS file you create. Create a new file called /templates/system/css/custom.css (or whatever you like) and rewrite the code segment in component.php to look like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/custom.css" type="text/css" />
Now you can just code out your own CSS in the new custom.css file you created. You can do this with any template system from RocketTheme or YooTheme just as easily. In fact, if you use one of their templates, they probably already have a custom.css file that you can simply add your own code to. Just be aware if you do it that way and then later update the template, you'll lose your code additions. That's why I prefer writing my own file. You can probably do something very similar to include custom JS code, but I tend to avoid JS like the plague, so someone else will have to address how to link out to a custom JS file.