Advertisement:

The .template.php file for Posting View

Aloittaja Jamora1124, elokuu 20, 2013, 02:14:32 IP

« edellinen - seuraava »

Jamora1124

I was reading here that the general layout of the forum are four main templates. Well, I was wondering which template to use for editing the Post reply page? Or the quick reply? I wanted to slightly change the layout of that page. I wanted to add a drop-down menu right under the Message Icon selection, and then afterwards when the post is submitted, do an SQL update to a certain table.

Arantor

The main posting area (which also handles the main reply/edit post stuff) is in Post.template.php.

The quick reply is in Display.template.php.

Adding to the template is one thing, adding the actual query will be in Post.php regardless because both posting new topics, new posts/replies and saving of edits are handled there.
Holder of controversial views, all of which my own.


Jamora1124

Ok, do you know where to look for in the code when it starts a newtopic/reply?

Arantor

Um... new topic, new reply, edit post are *all* handled in the same piece of code.
Holder of controversial views, all of which my own.


Jamora1124

If I add require("SSI.php") to any of these files, it shouldn't cause a problem should it? I noticed that none of these have the SSI required thing, nor do they use any of the global variables.

Arantor

Why do you want to add SSI.php to the core code? You're *really* not supposed to do that. Under some setups it will break your forum entirely.
Holder of controversial views, all of which my own.


Jamora1124

I had a feeling about that. Well, I wanted to because it's easier for me to access the variables I need. For example, I know from working on my own pages that if I use $user_info['id'], I'll get the id of a user.

Can you perhaps show me where a post is validated in Post.php?

Arantor

Or you could just global $user_info and use that... no SSI required.

As for Post.php, it's the second HALF of the file, everything in Post2() deals with validation and saving, along with Subs-Post.php that actually commits the changes to the DB.
Holder of controversial views, all of which my own.


Jamora1124

Okay thanks, it looks like there's gonna be a lot of joint-coding, which can be fun. Also, thanks for the tip about globalizing $user_info. I'm not familiar with global variables. Hell, I'm only coding as a hobby so I'm pretty much a novice at this entire thing.

Jamora1124

Ok, so I managed to figure out how to add my drop-down menu as you can see in the screenshot. However, I only want this menu to appear on certain boards. For example, I want the menu to appear on boards with the id = 3 || 4 || 5 || 6.

I'm not entirely too familiar with SMF's template files. This entire time I've been building codes and pages that add to the forum completely from scratch. I've been using SSI and other built-in functions like $smcFunc. Though, it has come to my attention that using some of these variables within the template files and Source files will cause an error. So I was wondering, how do I pull the id of a board without using the those functions and variables?

Arantor

Well, the global variables are just that, global.

Just globalise $board inside your code and check against that.
Holder of controversial views, all of which my own.


Jamora1124

So if I were to simply add

<?php global $user_info$board?>

It will allow me to pull the info I need?


global $user_info,  $board;

if($board['id'] = 3 || 4 || 5 || 6)
{
execute some code
}


That would be the basic example right? Do you think this would work fine in between an echo?

Arantor

Um... Not like that.

I was thinking more of
if (in_array($board, array1,2,3,4))

The posting area shouldn't be overwriting $board, which should always be the current board id.
Holder of controversial views, all of which my own.


Jamora1124

Here's what I did. It doesn't work. I'll try your approach next.

foreach ($context['icons'] as $icon)
echo '
<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected="selected"' : '', '>', $icon['name'], '</option>';

echo '
</select>
<img src="', $context['icon_url'], '" name="icons" hspace="15" alt="" /></dd>';
if($board['id'] == 3) {
echo '<dt class="clear_left">
Select Character: </dt>
<dd><select name="character" id="character">
<option value="1">Active Character #1</option>
<option value="2">Active Character #2</option>
<option value="3">Active Character #3</option>
</select></dd>
</dl><hr class="clear" />'; }
else {
echo '
</dl><hr class="clear" />'; }

Jamora1124

Okay, so I got it to work. Now, I can't get it to display in certain boards. Here's my code.

if($context['current_board'] == 3) {
echo '<dt class="clear_left">
Select Character: </dt>
<dd><select name="character" id="character">
<option value="1">Active Character #1</option>
<option value="2">Active Character #2</option>
<option value="3">Active Character #3</option>
</select></dd>
</dl><hr class="clear" />'; }
else {
echo '
</dl><hr class="clear" />'; }


Right now, it only shows for the board with the id of 3.

Arantor

Well, when you tried to use $board, did you bring it into scope with the global keyword? Did you use $board or $board['id'] ?
Holder of controversial views, all of which my own.


Jamora1124

I used $board['id'] because I figured I was trying to get the board id, since all of the id's in the database are different. I figure I can use board_id's an as identifier. I'm going to try a globalized $board now and see what happens. It worked well with $context['current_board'] but not $context['current_board']['id'].

Arantor

LainaaI used $board['id'] because I figured I was trying to get the board id

No wonder it didn't work because it's NOT that. It is, as I stated, just $board. Good luck on this, I'm out for future questions (because I'm sorry but I'm not going to offer support to someone who asks a question, gets an answer then goes off and does something else and wonders why it doesn't work, I don't have time for that, sorry)
Holder of controversial views, all of which my own.


Jamora1124

#18
I was getting confused. Once again, I've never globalized $board, so I don't entirely know the properties of the variable. It's all new to me. Also, it appears that $board doesn't work either.

EDIT/

I've also tried using an array but it didn't work. Works fine with if($board == 3 or $board == 4) etc.

Advertisement: