Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: bahgheera - joulukuu 07, 2013, 09:14:04 IP

Otsikko: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 09:14:04 IP
Hi folks, I have a question about adding code to only the index page of my smf site. So what I want to do is have a div that displays only on index.php. I have been researching the $context variable all evening, I can't believe there's no thorough explanation of it somewhere. Does anyone know how this can be done? Thanks in advance for any help on this.
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 09:38:26 IP
Everything runs through index.php - literally everything in SMF.

So, what are you trying to display where exactly?
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 09:53:51 IP
Lainaus käyttäjältä: ArantorEverything runs through index.php - literally everything in SMF.

Right, but I don't know the $context variable well enough to use it to check which page of the site a user is currently on.

If you go to the site http://www.theflipsideforum.com, you'll see the scroller script up top. I want this to only display on the index page. It seems like I could use one of smf's variables to check for this and either display the content or not.

I printed out the $context array and started digging through it, but the thing is so huge that it might take me days just to get it properly formatted to a point where I can even begin to make sense out of it.
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 09:55:27 IP
Well, how did you add it in the first place? That's not a standard part of SMF...
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 09:59:47 IP
No, it was custom code that I added.
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 10:01:09 IP
Yes, I already know that. HOW did you add it? Where did you add it?

A quick glance at the code suggests you shoved it in index.template.php, when the proper place is probably BoardIndex.template.php.
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 10:03:06 IP
Ah. Well, in that case, yes that's what I did. I added it to index.template.php.
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 10:03:55 IP
So you should move it from the 'shown on every page' template to the 'shown on the list of boards' template like I mentioned.
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 10:06:58 IP
So there's no way to use the $context variable or another variable to check which page I'm on?
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 10:15:40 IP
I'm telling you that you don't need to.
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 10:18:20 IP
Ok... so do you know the answer to my original question?

If I put it in boardindex, then it will be outside the part of the header that is hidden when user clicks the upshrink button.
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 10:25:10 IP
You didn't tell me you wanted it kept inside the upshrinker. It's really frustrating trying to deal with people who only tell me what they think I need to know as opposed to all the relevant information.

There is no master $context variable that you can use in this situation (which is why I suggested using the board index template which is the only *absolutely* guaranteed thing to be there on the board index page)

In this case you can only infer it indirectly from other probable contents of $context. $context['categories'] is one variable but this will be populated elsewhere in the software, so that on its own is not enough. Fortunately you don't seem to be using a portal, so isset($context['categories'], $context['show_buddies']) && function_exists('getMembersOnlineStats') might work for you.
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 10:35:46 IP
Lainaus käyttäjältä: ArantorYou didn't tell me you wanted it kept inside the upshrinker. It's really frustrating trying to deal with people who only tell me what they think I need to know as opposed to all the relevant information.

It's only as frustrating as you make it. I didn't tell you what you needed to know simply because I didn't know you'd need to know that. Honestly, I thought I was being polite and as verbose as I could.

Thank you for the answer.
Otsikko: Re: Custom code on front page only?
Kirjoitti: Burke ♞ Knight - joulukuu 07, 2013, 10:37:05 IP
Looks like the OP wants the slider so it is not affected by the upshrink.
As for his statement of which page he's on, well, he better know what page he's editing, because we sure can't tell him what he's doing.

Seems to me that the slider is supposed to be everywhere, but he is confusing himself, with the upshrink area.


As for that, YES any info on what you are trying to do is needed!
Otsikko: Re: Custom code on front page only?
Kirjoitti: Arantor - joulukuu 07, 2013, 10:41:04 IP
That's why I asked you how you added it and where you added it... in normal circumstances the proper course of action would be the one I gave you.

As for 'as difficult as I make it', I'm not prone to giving out advice to people without understanding whether I'm giving them the *right* advice. Or whether I should be advising them to change things to do it more cleanly/better/faster.

Best of luck with it.

LainaaLooks like the OP wants the slider so it is not affected by the upshrink.

No, he said he wanted it there so it WILL be affected by the upshrink which is why moving it to the board index template would not be the proper course of action.

LainaaSeems to me that the slider is supposed to be everywhere, but he is confusing himself, with the upshrink area.

No, he wants it in the upshrink area but only on the board index. We already established this, I gave probably the best answer to deal with it and will now henceforth be leaving this topic alone to stop me getting frustrated. (But this is why I shouldn't really do support, because it only ends up annoying me, despite being the best way to gauge how users need SMF to change in future.)
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 07, 2013, 10:44:36 IP
Sorry for the misunderstanding.
Otsikko: Re: Custom code on front page only?
Kirjoitti: bahgheera - joulukuu 10, 2013, 01:01:57 AP
So for anyone interested, I solved this. After poring through the $context array, I discovered something that appears to work - the $context[linktree] variable. I simply surrounded my upper_section div in index.template.php with if (!$context[linktree][1]) and it seems to be working perfectly. If I run into any problems with this method I'll report back here.

@BurkeKnight - lol wat?