Page 1 of 1

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

Posted: Sun Jan 13, 2008 10:54 am
by tungolcild
Hi, am here again...trying to complete a second project (harder on this time, I think :pop)

Wish me good luck....

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

Posted: Sun Jan 13, 2008 6:02 pm
by shantanubala
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

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

Posted: Sun Jan 13, 2008 6:17 pm
by tungolcild
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?

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

Posted: Sun Jan 13, 2008 7:28 pm
by shantanubala
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

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

Posted: Mon Jan 14, 2008 8:03 pm
by Chris Davenport
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.

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

Posted: Mon Jan 14, 2008 8:36 pm
by tungolcild
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

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

Posted: Wed Jan 23, 2008 6:31 pm
by AmyStephen
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

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

Posted: Tue Jan 29, 2008 1:57 am
by AmyStephen
tungolcild -

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

Thanks!
Amy :)