Interspire Product Knowledge Base

Would you like to...

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favorites Add to favorites

Remove Highlighting Remove Highlighting

Edit this Article

Export to PDF

User Opinions (0 votes)

No users have voted.

How would you rate this answer?



Thank you for rating this answer.

The template config.php file

The Template config.php File

Each template will have a config.php file located in the root folder. This file is parsed before any other template code. This is handy for running PHP specific code for the template, or checking for specific conditions. Any PHP code can be placed in the file. Please note that it is recommended that you do not directly output content from this file, but rather store your content into global variables (see above).

This file can be used to override certain settings. For example, if a certain template is designed to have 1 feature article, and having any more would break the design, then this file can force the user's settings to only allow 1 featured article with a just one line:

$GLOBALS["AL_CFG"]["NumFeaturedArticles"] = 1;

If you are an advanced PHP user you will find this file useful for customizations. There are also some functions that are useful for this file. They are conditional functions that return true or false. They can be used in 3 ways; No argument just checks to see the content type of the current page, or pass in a integer of a content ID, or pass in an array of content ID numbers.

One such function is: is_category() Used without any argument, this will return true if viewing a category. If you pass in a integer, this will return true only if the number matches the current category ID being viewed. The last option is to pass in an array of integers, the function will return true if any one of the values is the category being viewed.

The three other functions are: is_article(), is_blog() and is_page(). These functions work exactly the same as the is_category() function but with their respective content types.

There is a fifth function that is available: is_article_category() This works as an extension of the is_article() function, but does not function without an argument. You must pass an integer or array to it. Similar to the other function, it will check firstly that you're viewing an article, but then will check if the article is in any of the category ID's you pass to it as an integer or array.

ID numbers for content types can be found in the control panel, either as a column when managing the content type or in the 'Edit' link for each item.

Here are some examples using the code above:

Using the is_category() function. Lets say we have a category called "Example" with an ID number of 5:

<?php

if( is_category(5) ){
    
// we're in the category we want
   
$GLOBALS['MyVariable'] = "Welcome to the Example category";
}else{
    
// we're not in the category we want
   
$GLOBALS['MyVariable'] = "You're currently not in the Example category. Would you like to go there?";
}

?>

We can then use the %%GLOBAL_MyVariable%% placeholder where we want in our HTML files, and the value of it will change depending on the category we're in. The above example passes in a single integer to check. Our next example shows how to do this with an array:

<?php

if( is_category(array(5,2,10)) ){
    
// we're in one of the categories we want
}

# or you can pass in a variable that is an array

$var = array(5,2,10);
if( 
is_category($var) ){
    
// we're in one of the categories we want
}

?>

This method thus allows greater flexibility over template usage. This can be extended to do other things, such as overriding a template. For example, we have our default Articles.html file, but we have 1 category where we would like the articles to use a different file, Articles_Alternative.html. This is some code we could use:

if(is_article_category(5)){
    
$template = &GetClass('template');
    
$template->SetTemplate('Articles_Alternative');
    
$template->_tplData $template->_LoadTemplateFile();
}

This will override the Articles.html file with the Articles_Alternative.html file for any articles in the category with ID 5.


Related Articles

No related articles were found.

Attachments

No attachments were found.

Powered by Interspire Knowledge Manager - World's #1 Best Selling FAQ and Knowledge Base Software