Joomla Conditional Statements

Discussion in 'PHP/MySql' started by balajia, Jul 7, 2010.

Remove these ads by signing in
Remove these ads by signing in
  1. balajia New Member

    Member Since:
    Jul 1, 2010
    Message Count:
    27
    Likes Received:
    1
    Occupation:
    Web Developer
    Location:
    India
    cond1:
    <?php if($this->countModules('condition')) { ?>
    do something
    <?php } else { ?>
    do something else
    <?php } ?>


    explanation:
    Controls what actions the template's index.php file takes depending on the current state of a module or a
    set of modules



    cond2:
    <?php if(JRequest::getVar('view') == ('current_view') { ?>
    do something
    <?php } else { ?>
    do something else
    <?php } ?>

    explanation:
    Control what actions the template's index.php file takes depending on the
    current view, e.g., article, category, section, contact, etc.
    Although this can be used to determine if the current view is the
    front page ('frontpage'), the Joomla! core developers recommend use of J
    Site::getMenu(), $menu->getActive, and $menu->getDefault to determine if the current
    view is the front page.



    cond3:
    <?php $menu = &JSite::getMenu(); ?>
    <?php if ($menu->getActive() == $menu->getDefault()) { ?>
    do something
    <?php } else { ?>
    do something else
    <?php } ?>

    explanation:
    Control what actions the template's index.php file takes if it is the front page versus other pages.



    cond4:
    <?php

    $userattr = JFactory::getUser();
    $condition = $userattr->get('attribute')
    if($condition == 'return value') { ?>
    do something

    <?php } ?>


    explanation:
    'attribute' is one of the following;

    'id' – user id
    'name' – user name
    'aid' – defines the user access identifier and acts in the same way as the gid in Joomla! 1.0.x (normally this is 0 for for public, 1 for registered and for for special). The aid is used against the systems access database fields to define if the user can access a certain database res
    'gid' – defines the actual acl user group identifier (19, author, 20 editor, 22 publisher, 23 manager, 24 administrator, 25 super administrator
    'guest' – defines if a user is logged in or not (when logged in guest is 0)
    'usertype' – user type (Registered, Author, Editor, Publisher, Super Administrator, Adminiistrator, Manager)
    1 people like this.

Share This Page