|
Page 1 of 1
|
Vortex
Joined: October 2006
Posts: 412
Location: Prato, Italy
|
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
'T_HIDDEN_COLOR' => '#' . $theme['hidden_color'],
AFTER ADD
'MY_CUSTOM_VAR' => $my_custom_var,
Then, recall your var in the .tpl file you need it, using the following:
Original post:
Hi all ^^
I have to create a new var and use it on the template but I couldn't succeed yet. I followed the advises I found on the phpBB site and did:
assign var in common.php (because I think is called on every page generation of my site, tell me if this is not true)
$template->assign_var('VORT_POP' , $vort_pop );
and recall it in overall_header.tpl
<a href="{VORT_POP}"> link blah blah </a>
but I got a
Quote:
Fatal error: Call to a member function assign_var() on a non-object in .../common.php
Where am I wrong?
Thanks for the help
Last edited by Vortex on Mon 18 Feb, 2008 07:38; edited 3 times in total |
#1 Fri 15 Feb, 2008 12:50 |
|
Sponsors
|
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.
|
|
KasLimon
Joined: November 2006
Posts: 494
Location: Madrid (Spain)
|
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 'T_HIDDEN_COLOR' => '#' . $theme['hidden_color'],
With this syntax: 'NAME_VAR' => $something,
And in template:
Greets!
____________ Gabriel Anca
|
#2 Fri 15 Feb, 2008 13:38 |
|
Vortex
Joined: October 2006
Posts: 412
Location: Prato, Italy
|
Re: How To Add A New Var For Template
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 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 ^^
|
#3 Fri 15 Feb, 2008 13:51 |
|
Vortex
Joined: October 2006
Posts: 412
Location: Prato, Italy
|
Re: How To Add A New Var For Template
Ok just saw you edited the post ^^
In page_header.php I noticed:
// 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 !!!
|
#4 Fri 15 Feb, 2008 14:00 |
|
KasLimon
Joined: November 2006
Posts: 494
Location: Madrid (Spain)
|
Re: How To Add A New Var For Template
So I suppose my function goes above that, and then I can set any variables I want in the following huge array, right?
Yes
____________ Gabriel Anca
|
#5 Fri 15 Feb, 2008 14:10 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7192
Location: Borgo San Michele
|
Re: How To Add A New Var For Template
Great KasLimon, you are doing great PHP support.
Thank you.
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#6 Fri 15 Feb, 2008 21:55 |
|
novice programmer
Joined: June 2007
Posts: 1030
Location:
|
Re: How To Add A New Var For Template
I think this should be in the section for tutorials. moving...
|
#7 Sun 17 Feb, 2008 21:48 |
|
Vortex
Joined: October 2006
Posts: 412
Location: Prato, Italy
|
Re: How To Add A New Var For Template
Edited first post to make it fit better with the "How To" section
|
#8 Mon 18 Feb, 2008 07:37 |
|
Press 22
Joined: June 2007
Posts: 101
Location:
|
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.
____________ Running two Icy forums on one server
|
#9 Mon 18 Feb, 2008 07:54 |
|
Sarakin
Joined: September 2008
Posts: 143
|
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 ) 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
____________ Support Info
Ivory Tower URL: : http://www.torredemarfil.es/foro/ Version: 2.0
|
#10 Mon 22 Sep, 2008 19:08 |
|
Inactive User
|
Re: How To Add A New Var For Template
Check this out
h**p://***.icyphoenix.com/viewtopic...&p=26605#p26605
|
#11 Tue 23 Sep, 2008 15:47 |
|
Sarakin
Joined: September 2008
Posts: 143
|
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?
____________ Support Info
Ivory Tower URL: : http://www.torredemarfil.es/foro/ Version: 2.0
|
#12 Tue 23 Sep, 2008 19:58 |
|
Inactive User
|
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
|
#13 Sun 28 Sep, 2008 08:41 |
|
Sarakin
Joined: September 2008
Posts: 143
|
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?
|
#14 Sun 28 Sep, 2008 10:30 |
|
|
Page 1 of 1
|
Was this topic useful?
Was this topic useful?
Link this topic |
URL |
|
BBCode |
|
HTML |
|
Similar Topics
Similar Topics
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
|
|
|
|