Documentation 2.x and 3.x

Frequently used code snippets

Generate internal link

All links on the page should be generated through global variable $site.

<?php
global $site;

//public function generateUrl($languageId=null, $zoneName = null, $urlVars = null, $getVars = null);

$site->generateUrl(); //link to main page of current language
$site->generateUrl($languageId); //link to main page of specified language
$site->generateUrl(null, 'zoneName'); //link to first page of specified zone
$site->generateUrl(null, null, array('url1', 'url2'), array('get1'=>'val1', 'get2'=>'val2')) //link to current language current zone with following suffix: /url1/url2/?get1=val1&get2=val2
?>

Get variable / option / translation from configuration

Use global variable $parametersMod to get modules configuration values or translations.

You can preview all configuration values and create new ones through Developer -> Modules config.

Common values are also accessible in Standard -> Configuration.

<?php

//Here is an example that prints copyright message from configuration:

global $parametersMod;
echo $parametersMod->getValue('standard', 'configuration', 'translations', 'copyright'); //will output copyright notice.
?>

Generate link to your image or CSS file in theme

<?php

//use it in your theme file. Eg. ip_themes/lt_pagan/main.php

echo BASE_URL.THEME_DIR.THEME.'/your.css'; //link to css file in your theme
echo BASE_URL.THEME_DIR.THEME.'/images/logo.jpg'; //link to image in your theme

?>

Generate menu

<?php

//use it in your theme file. Eg. ip_themes/lt_pagan/main.php

require_once(LIBRARY_DIR.'php/menu/common.php'); //include menu generation class
$menuTop = new Library\Php\Menu\Common(); //create object
echo $menuTop->generate('top'); //generates menu list. Replace top to any other zone name

echo $menuTop->generate('top', $startDepth, $depthLimit); //you can limit menu depth. If $startDepht and $depthLimit are 2 and 3 respectively, then function will output tree levels of menu starting from second level.

echo $menuTop->generateSubmenu('top', $parentElementId, $depthLimit); //you can print menu by starting from children of particular element. 


?>

Generate language selection box

<?php

//use it in your theme file. Eg. ip_themes/lt_pagan/main.php

require_once (BASE_DIR.MODULE_DIR.'standard/languages/module.php');
echo \Modules\standard\languages\Module::generateLanguageList();
?>

Generate breadcrumb

<?php

//use it in your theme file. Eg. ip_themes/lt_pagan/main.php

require_once(MODULE_DIR.'standard/breadcrumb/module.php');
echo \Modules\standard\breadcrumb\Module::generateBreadcrumb(); //genearates breadcrumb with links
echo \Modules\standard\breadcrumb\Module::generateBreadcrumb($separator); //$separator - html code to separate elements.

?>

Generate page content

<?php 

//use it in your theme file. Eg. ip_themes/lt_pagan/main.php

echo $site->generateBlock('side');
 
?>

Write a comment

You must be logged in to comment.