092 - Write a document on PHP essentials for template designers.

Google's Highly Open Participation Program tries to get young students into Open Source and Joomla! specifically. Everyone is welcome, there are not limits. You can be a coder, documenter, tester, translator to help out. Jump in and start helping!
tungolcild
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Thu Jan 03, 2008 11:39 am
Contact:

092 - Write a document on PHP essentials for template designers.

Postby tungolcild » Sun Jan 13, 2008 10:54 am

Hi, am here again...trying to complete a second project (harder on this time, I think :pop)

Wish me good luck....
Last edited by AmyStephen on Mon Feb 04, 2008 8:19 am, edited 1 time in total.

shantanubala
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 141
Joined: Thu Nov 29, 2007 9:41 pm

Re: 092 - Write a document on PHP essentials for template designers.

Postby shantanubala » Sun Jan 13, 2008 6:02 pm

Hey! If you need any help, just let me know. I've been working with 1.5 templates a lot lately and would be glad to help.

Good luck!
-Shantanu
http://joomlacode.org/gf/project/jkids/ Joomla! Kids - the Project aimed at making Joomla! more kid friendly!

tungolcild
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Thu Jan 03, 2008 11:39 am
Contact:

Re: 092 - Write a document on PHP essentials for template designers.

Postby tungolcild » Sun Jan 13, 2008 6:17 pm

Thank you for your response! 8) On the otherside I have not so much experience with templates...I have downloaded some from different sources and looking at the code....What do you believe are the most important (php) elements for a template designer?

shantanubala
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 141
Joined: Thu Nov 29, 2007 9:41 pm

Re: 092 - Write a document on PHP essentials for template designers.

Postby shantanubala » Sun Jan 13, 2008 7:28 pm

Ok, here are a few that I use *really* often. If you need some more examples, most of this code is stuff I've already written, so I'll gladly share it with you.

Code: Select all

$this->template

it returns template's directory for linking images, stylesheets, and javascript files.
A good example of this is

Code: Select all

<img src="templates/<?php echo $this->template; ?>/images/something.png">

---------------------
Another good php variable is

Code: Select all

JURI::base()

which returns the url of the Joomla installation (i.e. http://yourjoomlasite.com )
An example is

Code: Select all

<a href="<?php echo JURI::base(); >">Home</a>

Another version of this is the

Code: Select all

$this->baseurl
variable, which returns a relative path to the joomla install without the "http://yoursite.com"
---------------------
A noteworthy variable for templates is:

Code: Select all

$this->countModules('condition')

Used for the current state of modules in a PHP conditional such as

Code: Select all

<?php if($this->countModules('user3')) : ?>
   <div id="topbar">
      <jdoc:include type="modules" name="user3" style="xhtml" />
   </div>
<?php endif; ?>

---------------------
This variable:

Code: Select all

JRequest::getVar('view')
returns the the current view, or whatever the page is currently displaying (i.e. "frontpage", etc.)
This is useful for determining what action a template takes depending on what content is being viewed.
so if you want something specific to happen on the article view, you'd do something like this:

Code: Select all

<?php if(JRequest::getVar('view') == ('article') { ?>
    [Insert whatever here]
<?php } else { ?>
     [Insert whatever here]
<?php } ?>

BUT for the frontpage, there is a better option SPECIFIC to only the frontpage, unlike this one which allows you to create conditionals for all the different content views.
This frontpage option is this conditional-->

Code: Select all

<?php $menu = &JSite::getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()) { ?>
     [Insert whatever here]
<?php } else { ?>
    [Insert whatever here]
<?php } ?>

---------------------
Lastly you can define specific template functions for different levels of users, guests, administrators, etc.

Code: Select all

<?php
$theuser = JFactory::getUser();
$usertype = $theuser->get('[Insert attribute here]')
if($usertype == '[Insert attribute value here]') { ?>
    [Insert whatever here]
<?php } ?>


You'll probably notice that I put a "[Insert attribute here]" - that means to insert one of the following:
id: which is the user ID number
name: which is the username
aid: which is the user access identifier (i.e. 0 for public, 1 for registered, and 4 for special)
gid: which is the actual usergroup the user is in (i.e. 19 for author, 20 for editor, 22 for publisher, 23 for manager, 24 for administrator, and 25 for super administrator
guest: pretty self explanatory (when logged in the guest variable is 0)
usertype: which is the usertype, except it returns that usertype as a string (registered, author, editor, publisher, manager, administrator, and super administrator)

You'll probably notice that I put a "[Insert attribute value here]" - this means take one of the return values stated above for each attribute, and use it as the qualifying value for the conditional statement.

HTH
-Shantanu
Last edited by shantanubala on Sun Jan 13, 2008 7:34 pm, edited 1 time in total.
http://joomlacode.org/gf/project/jkids/ Joomla! Kids - the Project aimed at making Joomla! more kid friendly!

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1383
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: 092 - Write a document on PHP essentials for template designers.

Postby Chris Davenport » Mon Jan 14, 2008 8:03 pm

Hi,

I don't want you to go off on a tangent with this task.  Read the task description carefully.  The idea is that many people who work on Joomla! templates are designers, such as graphic artists, who have little or no knowledge of the PHP language.  You can assume that they have at least a basic knowledge of HTML/CSS.  If you scan the template forums you will often see questions about PHP itself.  So this task is just a basic introduction to the kinds of PHP statements that are commonly seen and used in templates.  It's not about Joomla!, its API or any of the variables that you have access to.  That should be documented elsewhere.

So, for example, you will need to explain about the tags; the echo/print statement; if-then-else constructs and so on.  It doesn't need to be hugely detailed; we're not looking for a PHP reference manual here.  Keep the target audience in mind and show them what they need to know about PHP so they can get their jobs done.

Hope that clarifies.  :)

Any questions, just ask.

Chris.
Chris Davenport - Joomla Production Leadership Team

Lion Coppice http://www.lioncoppice.org/
Davenport Technology Services http://www.davenporttechnology.com/

tungolcild
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Thu Jan 03, 2008 11:39 am
Contact:

Re: 092 - Write a document on PHP essentials for template designers.

Postby tungolcild » Mon Jan 14, 2008 8:36 pm

Nice. So I will make a list with what my document will cover (I have already done some things) and I will upload here a first draft..Thank you

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 092 - Write a document on PHP essentials for template designers.

Postby AmyStephen » Wed Jan 23, 2008 6:31 pm

tungolcild -

If you get a chance, can you please let us know where you are at on this task? It's been over a week since we have heard from you.

Thanks!
Amy

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7056
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 092 - Write a document on PHP essentials for template designers.

Postby AmyStephen » Tue Jan 29, 2008 1:57 am

tungolcild -

We are reminding people that this is the last week of the contest.

Thanks!
Amy :)


Return to “Google's Highly Open Participation Contest”

Who is online

Users browsing this forum: No registered users and 1 guest