Skip to main content

Introduction to Joomla! Api’s

Joomla! provides us with some functions so, you can add the Javascript in the correct place, this functions can be called from anywhere in the code and they will not break compatibility with the XHTML standard. These functions are addScriptDeclaration and addScript they allow us to insert Javascript code and insert a Javascript (.js) file.


Adding Javascript using the addScript function:

If you will like to add a external .js file you will use the addScript function and pass as a argument the path and name of the .js file you should also specify the whole path of your Javascript file by using the JURI:base function. In this case, the hello.js file is in the root folder of the Joomla! installation.

In a template you will call it the following way using the this variable, because the template is called by the document class where the addScript function is located.

Note: we add JURI::base() before the hello.js to prefix the path of the folder where Joomla! resides and $this->template to get the name of the folder where the template resides.


// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

$js = "/templates/".$this->template."/hello.js";

$this->addScript(JURI::base() . $js);

?>



If you where calling this from a component or module you will need to get the document reference using this line of code. This line of code will store the document reference into the document variable.


$document =& JFactory::getDocument();


And call the function to add the javascript file.

Note: we add JURI::base() before the hello.js to prefix the path of the folder where Joomla! resides.



defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');


class AlliesViewAllies extends JView

{

function display($tpl = null)

{

global $mainframe, $option;

$document =& Jfactory::getDocument();

$js = "/templates/".$this->template."/hello.js";

$document->addScript(JURI::base() . $js);


Adding Javascript using the addScriptDeclaration function:

If you will like to add a small piece of Javascript code you will use the addScriptDeclaration function. Example:

If you are calling it inside a template you will use the $this variable and inside the double quotes you will pass it Javascript code in this case an alert function that will display Hello Joomla! To the user.


// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

$this->addScriptDeclaration("alert('Hello Joomla!')");

?>


If you will like to add this Javascript from a module or a component you will do it by getting a reference of the document using the getDocument Function:


$document =& Jfactory::getDocument();


And now you call the function using the document variable


$document->addScriptDeclaration("alert('Hello Joomla!')");


the code will like like this


defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');


class AlliesViewAllies extends JView

{

function display($tpl = null)

{

global $mainframe, $option;

$document =& JFactory::getDocument();

$document->addScriptDeclaration("alert('Hello Joomla!')");


  • default menu item is of type front page layout


padding-left: 10px; padding-right:10px; padding-top: 5px; padding-bottom:5px;

margin-left: 0px; margin-right:0px; margin-top: 0px; margin-bottom:0px;


by adding margin column in a hover the menu appears different




---- is used to display the articles ..etc


Joomla maintains a media manager to insert images ..media manager is in article content bottom


countModules('left')) : ?>-----module title will display only if we use this tag


defined( '_JEXEC' ) or die( 'Restricted access' );--- it is used to not allowing the direct access of the web pages  

Comments

Popular posts from this blog

Create or Customize Master Page in sharepoint

Before using the base master page,please fimiliare yourself with various sections of the base master page code · Required Components · Optional Components · Hidden Components Required Components: If no availability of required components sharepoint page cannot render properly All the components are placed in a their corresponding content place holder asp:ContentPlaceHolder id=”PlaceHolderMain” runat=”server” /> This content placeholder corresponds to the content area in page layouts.It is required for the MOSS site to render properly. All the required which are not usefull should be placed .If you delete those place holders sharepoint page cannot render properly Following are the some of the required components asp:ContentPlaceHolder id=”PlaceHolderMain” runat=”server” /> asp:ContentPlaceHolder id="PlaceHolderGlobalNavigation" runat="server"> asp:ContentPlaceHolder id="PlaceHolderTopNavBar...

Using Friendly URLs(SEO) in Joomla

In folder apacheconf open file httpd.conf #LoadModule rewrite_module modules/mod_rewrite.so and make it as uncommented LoadModule rewrite_module modules/mod_rewrite.so In site root folder there is rename htaccess.txt to .htaccess and now open .htaccess and go to following line # RewriteBase / and uncomment this line as following and mention root for ex. testsite in following line RewriteBase /testsite Go in administrator panel and click on Global coniguration Here on right side we get SEO Settings all three SEO Settings set as yes and click on save

Randomly Displaying a Single SharePoint Item on Refresh

This is how: 1. Create a new Data View web part in SharePoint Designer that displays all records in the format you want. We will end up only showing one record, so keep that in mind when you are laying this out. 2. Open the Filter dialog 3. Do not add any clauses, instead check the Add XSLT Filtering box and click Edit 4. Create your XSLT filter. You can just paste in the following code: [position() = (substring(ddwrt:FormatDateTime(ddwrt:TodayIso(),1033,":mm:ss"),6,2) mod count(/dsQueryResponse/Rows/Row))+1] 5. Click Ok and save the page in SharePoint Designer 6. Check your work in your browser. Refresh the page to see the item rotate.