# How do I add new variable in a .TPL file

**URL:** https://forum.kirupa.com/t/how-do-i-add-new-variable-in-a-tpl-file/203216
**Category:** programming
**Created:** [October 9, 2006, 4:41am UTC](https://forum.kirupa.com/t/how-do-i-add-new-variable-in-a-tpl-file/203216 "2006-10-09T04:41:42Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![toasty](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@toasty](https://forum.kirupa.com/u/toasty)
#### Post date: [October 9, 2006, 4:41am UTC](https://forum.kirupa.com/t/how-do-i-add-new-variable-in-a-tpl-file/203216/1 "2006-10-09T04:41:42Z")

</div>

I need a solution to what’s bound to be a really simplistic problem. I’m running a php/mysql script on my site and one of the functions it performs to display a news/text post and dynamically link it to a corresponding image file. If you’re thinking “webcomic” you’re right on the money. The news posts are formatted according to a **.tpl** file.

The script itself is [Comikaze](http://www.comikaze.org) and I’ve tried contacting the creator, but I’ve not heard anything back for quite some time and after several attempts.

The thing I need help with is that I need to insert a link into that .tpl COLOR=red[/COLOR] file that will dynamically link from the news post to the corresponding image page. I’ve discovered that simply inserting PHP into the news\_print.tpl file does **not** work. What I thought I’d do would be to define a new variable that I’d be able to use inside the news\_print.tpl file.

Variables that already exist are [COLOR=red]{NES\_AVATAR}, {NEWS\_POST}, {NEWS\_DATE}, {NEWS\_POSTER}[/COLOR], and a few others.

The variable I need is already used by the script elsewhere as [COLOR=blue]$comic\_id[/COLOR]; the comic rotation/navigation uses it to, well “navigate.” However how to turn it into something that news\_print.tpl can use… that’s what I’m not sure about. I did some serious digging and I found this specific file that looks like it has to do with the news\_print.tpl, and is called [COLOR=red]newsDO.class.php[/COLOR]. Inside the code on line #48 begins the following code:

```auto
function formatNewsPost($poster,$email,$avatar,$title,$post,$time,$nl2br) {
    $post = $this->nl2brNewsPost($post,$nl2br);
    if (!empty($avatar))
        $avatar = "<img src=\"$avatar\" alt=\"$poster\" border=\"0\" />";
    $replace['{NEWS_POSTER}'] = $poster;
    $replace['{NEWS_EMAIL}'] = $email;
    $replace['{NEWS_AVATAR}'] = $avatar;
    $replace['{NEWS_TITLE}'] = $title;
    $replace['{NEWS_POST}'] = $post;
    $replace['{NEWS_DATE}'] = $time;
        
    return $this->_common->getTemplate('news_print.tpl', $replace);
}

```

I thought that if I added [COLOR=blue]$comic\_id[/COLOR] into the function call on the first line and the [COLOR=blue]$replace[’{COMIC\_ID}’] = $comic\_id;[/COLOR] down with the rest that this would allow me to use [COLOR=red]{COMIC\_ID}[/COLOR] as a variable with the news\_print.tpl file. Unfortunately, all it does when I attempt to use it is spits out this error:

```auto
Warning: Missing argument 8 for formatnewspost() in /var/www/html/smcomikaze/includes/classes/newsDO.class.php on line 48

```

My website is essentially done, this is the last bit of code I need to wedge into it and _poof_ off it goes. Once I can get this to work it’s keg time!

Thanks to anyone who’s taken the time to read this over!
