MyBB Community Forums

Full Version: [Request]Create a new template using php code and call it in other template?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all, i'm using forumicons with links on forumbit how can i make a thing like this?
I want to create a new template called "icon" and after write in forumbit "{$icon}".

$forumicon = {$theme['imgdir']}/icons/icon_{$forum['fid']}.png;
$forumiconurl = {$forum_url};

<a href="{$forumiconurl}"><img src="{$forumicon}" align="left" title="{$forum['name']}"></a>

if ($forumiconurl = {$theme['imgdir']}/icons/icon_71.png){
$forumiconurl = redirectlink;
}

and eventually add an esleif for other redirect forums....

Don't tell me how the hell i must do that, it's a long story xD.
I'm confused. PHP doesn't work in templates, and so I'm not sure where you want to put the above code, much less understand what you're trying to do with the code Toungue
(2009-04-15, 08:49 AM)Dennis Tsang Wrote: [ -> ]I'm confused. PHP doesn't work in templates, and so I'm not sure where you want to put the above code, much less understand what you're trying to do with the code Toungue

ok, I explain my problem:

In my "forumbit_depth2_forum" i added a forum icon near the forum name and description, like this:

[Image: forumicon.png]

but i added also a link on icon searching:

<td class="{$bgcolor}" valign="top">
<strong>
<a href="{$forum_url}">
{$forum['name']}
</a>
</strong>
{$forum_viewers_text}
<div class="smalltext">
{$forum['description']}
{$modlist}
{$subforums}
</div>
</td>

and replacing with:

<td class="{$bgcolor}" valign="top">
<a href="{$forum_url}">
<img src="{$theme['imgdir']}/icon_{$forum['fid']}.gif" align="left">
</a>
<strong>
<a href="{$forum_url}">{$forum['name']} 
</a>
</strong>
{$forum_viewers_text}
<div class="smalltext">
{$forum['description']}
{$modlist}
{$subforums}
</div>
</td>

well, now, i want to give to some icons another link (cause my mybb redirect on forum can't works) and i tried to use that code:

i created a new template called icon, and after i wrote that code inside:

$forumicon = {$theme['imgdir']}/icons/icon_{$forum['fid']}.png;
$forumiconurl = {$forum_url};

<a href="{$forumiconurl}"><img src="{$forumicon}" align="left" title="{$forum['name']}"></a>

if ($forumiconurl = {$theme['imgdir']}/icons/icon_71.png){
$forumiconurl = redirectlink;
}

and after i tried to install the php template mod (link over this post) using that:

<?php $immaginetarghetta = {$theme['imgdir']}/targhettesezioni/icon_{$forum['fid']}.png; ?>
<?php $forumurltarghetta = {$theme['imgdir']}/targhettesezioni/icon_{$forum['fid']}.png; ?>

<div class="iconeblink"><a href="{$$forumurltarghetta}"><img src="{$immaginetarghetta}" align="left" title="{$forum['name']}"></a></div>

<?php if ($immaginetarghetta = {$theme['imgdir']}/targhettesezioni/icon_71.png){ ?>
$forumurltarghetta = redirectlink;
<?php } ?> 

In practice i want to replace this code in "forumbit_depth2_forum"

<td class="{$bgcolor}" valign="top">
<a href="{$forum_url}">
<img src="{$theme['imgdir']}/icon_{$forum['fid']}.gif" align="left">
</a>
<strong>
<a href="{$forum_url}">{$forum['name']} 
</a>
</strong>
{$forum_viewers_text}
<div class="smalltext">
{$forum['description']}
{$modlist}
{$subforums}
</div>
</td>

with this, calling the template

<td class="{$bgcolor}" valign="top">
{$icon}
<strong>
<a href="{$forum_url}">{$forum['name']} 
</a>
</strong>
{$forum_viewers_text}
<div class="smalltext">
{$forum['description']}
{$modlist}
{$subforums}
</div>
</td>

did you understand now?

can anyone help me?

(sorry for not perfect english)
<td class="{$bgcolor}" valign="top">
<if $forum['fid'] == 71 then>
<a href="{$forum_url}">
<img src="{$theme['imgdir']}/icon_{$forum['fid']}.gif" align="left">
</a>
</if>
<strong>
<a href="{$forum_url}">{$forum['name']}
</a>
</strong>
{$forum_viewers_text}
<div class="smalltext">
{$forum['description']}
{$modlist}
{$subforums}
</div>
</td>
^ Something like that?
I sloved:

<if $forum['fid'] == 71 then>
<a href="redirectlink"><img src="{$theme['imgdir']}/icons/icon_71.png" align="left"></a>
</if>
<if $forum['fid'] > 71  then>
<a href="{$forum_url}"><img src="{$theme['imgdir']}/icons/icon_{$forum['fid']}.png" align="left"></a>
</if>
<if $forum['fid'] < 71  then>
<a href="{$forum_url}"><img src="{$theme['imgdir']}/icons/icon_{$forum['fid']}.png" align="left"></a>
</if>

ty all for helping Wink
ah another thing:

-is there a method to declare on if a disequal? like

<if 3 /= 2 then>
3 == 3
</if>
!= is your "not equal" sign.
and multiple not equal in 1 if cicle is possible? like:

<if 3 != 2 and 1 then>
3 == 3
</if>
No. The way to write such a thing is this:
<if condition= 3 != 2 && 3 != 1 <then>
<a href ... ></a>
</if>

1. between the "<if condition= <then>" and the "</if>" should be an html code or a javascript "snip" (not a PHP one) as this is inside a template.
2. Using "==" is for use inside an "<if <then>" statment. If you want a var to be asigned a value, you need to put it inside a javascript section.
(2009-04-15, 10:52 AM)okitai Wrote: [ -> ]No. The way to write such a thing is this:
<if condition=3 != 2 && 3 != 1 <then>
<a href ... ></a>
</if>

ty ^^ now i've finished ty very much to all for helping