CUSTOMIZATION - How To Add A New Var For Template


Subject: CUSTOMIZATION - How To Add A New Var For Template
PLEASE NOTICE: The original How To for this is due to KasLimon, as you can see from the following discussion. I edited this first post in order to have it all summarized, since it has been moved in this section, it will look more "how to" like and easy to read for the people who look for it ;)



How to create a new variable to use in the .tpl files



Assign your custom variable through the array for the common variables to be used in most part of the site:


In includes/page_header.php


FIND
Code: [Download] [Hide] [Select]
'T_HIDDEN_COLOR' => '#' . $theme['hidden_color'],




AFTER ADD
Code: [Download] [Hide] [Select]
'MY_CUSTOM_VAR' => $my_custom_var,




Then, recall your var in the .tpl file you need it, using the following:

Code: [Download] [Hide] [Select]
{MY_CUSTOM_VAR}







Original post:
Spoiler: [ Show ]

Last edited by Vortex on Mon 18 Feb, 2008 07:38; edited 3 times in total
Subject: Re: How To Add A New Var For Template
That happens because $template class is not defined yet, I think

It should be better to add the var to page_header.php,
Add what you want after
Code: [Download] [Hide] [Select]
'T_HIDDEN_COLOR' => '#' . $theme['hidden_color'],

With this syntax:
Code: [Download] [Hide] [Select]
'NAME_VAR' => $something,

And in template:
Code: [Download] [Hide] [Select]
{NAME_VAR}


Greets!

Subject: Re: How To Add A New Var For Template
KasLimon wrote: [View Post]
That happens because $template class is not defined yet, I think

Please tell me where exactly are you adding that.

Greets!



At the bottom of common.php (I chose common.php just because I suppose is recalled very frequently)


I have my own PHP function inside common.php. What it does doesn't matter actually, the important thing is that it ends with a single string I want to assign to a variable to use in the template. My function works good on a .php page, I just need to know how to integrate it in the template sistem.

Till now I've worked at .tpls only with html, so hard-coding things. I'd like to improve a bit learning how the .tpls' {VARIABLE} thingy works in the "php-side", since I've never done that :mrviolet: and I thought it would be nice to start with a single variable ^^ (template page is overall_header.tpl )


Thanks for answering and helping, is really appreciated ^^

Subject: Re: How To Add A New Var For Template
Ok just saw you edited the post ^^


In page_header.php I noticed:


Code: [Download] [Hide] [Select]
// The following assigns all _common_ variables that may be used at any point in a template.
$template->assign_vars(array(



Amazing, just what I looked for!



So I suppose my function goes above that, and then I can set any variables I want in the following huge array, right?


Trying and letting you know ;)



Edit: it works perfectly! This is quite a breakthrough for me! Really thanks KasLimon !!!

Subject: Re: How To Add A New Var For Template
Vortex wrote: [View Post]
So I suppose my function goes above that, and then I can set any variables I want in the following huge array, right?
Yes :)

Subject: Re: How To Add A New Var For Template
Great KasLimon, you are doing great PHP support.

Thank you. :mricy:

Subject: Re: How To Add A New Var For Template
I think this should be in the section for tutorials. moving...

Profile PM  
Subject: Re: How To Add A New Var For Template
Edited first post to make it fit better with the "How To" section ;)

Subject: Re: How To Add A New Var For Template
How can I use this to recall specific users post?

For example in profile.php recall the posts from the users profile.

Subject: Re: How To Add A New Var For Template
First of all, thanks for this wonderful CMS, specially the Forum features, is the most full equiped Soft I've found and one of the main reasons for upgrading my PHPbb site to Icy.

Second, my apologies for refloating this topic, but there are a pack of things I've need to learn about adding variables yet. As you may see on my PHPbb forum (about Heroes of Might and Magic saga, MG :mrgreen: ) I've made some doggy (miserly made) customizations like the special avatar (which is only a GIF image), which I'd like to make them well on Icy by adding new variables which should recall the SQL request I need.

Well, if I set a new variable, for example "$call_to_artifact" (to show the custom "medals") where should I enter the variable value exactly? I mean, I've checked out this topic and I've found out that the variable is defined somewhere forward inside the page_header.php, so the question is: Is that place anywhere we want or it depends on the kind of operations we want to make? Another question I'd like to solve is: Are we able to define the new variable like "include external_file.php" and after this to program what we want?

Greets and thank you very much in advance for your attention! And sorry for my cavern english :oops:

Profile PM  
Inactive User
Subject: Re: How To Add A New Var For Template
Check this out ;)

h**p://***.icyphoenix.com/viewtopic...&p=26605#p26605

Subject: Re: How To Add A New Var For Template
I had already watched those topics, but I don't want a blank template (if it's that what you mean). I only want to know where I should define the variable "$whatever" with all the PHP instructions I want, for example, an "include external_file.php". Maybe somewhere inside the own page_header.php (example) or in the common.php as it's written on this topic header post?

Profile PM  
Inactive User
Subject: Re: How To Add A New Var For Template
Then obviously you didn't read very much because you should find all the answers you are seeking here - Which is linked from the url I posted earlier. ;)

h**p://***.icyphoenix.com/viewtopic...&p=30485#p30485

Subject: Re: How To Add A New Var For Template
You're right, I didn't search very well. I saw a lot of code and the label "Blank Template MOD" and I didn't pay much attention. I don't want to create a Custom page with a self-made Template. I only want to set the variables and, although I can't understand what are the whole code aimed for, I guess there's no need of most things you've shown there, like a template.php file. What I've understood of all the code is that I've got just put an "include newvariables.php" elsewhere and define them on this last php. The thing I want to know is "where" and "how" should I set the "include newvariables.php", into page_header.php?

Profile PM  

Page 1 of 1


  
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Generation Time: 0.3179s (PHP: 50% SQL: 50%)
SQL queries: 15 - Debug Off - GZIP Enabled