Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Custom code on front page only?

Aloittaja bahgheera, joulukuu 07, 2013, 09:14:04 IP

« edellinen - seuraava »

bahgheera

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.

Arantor

Everything runs through index.php - literally everything in SMF.

So, what are you trying to display where exactly?
Holder of controversial views, all of which my own.


bahgheera

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.

Arantor

Well, how did you add it in the first place? That's not a standard part of SMF...
Holder of controversial views, all of which my own.


bahgheera


Arantor

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.
Holder of controversial views, all of which my own.


bahgheera

Ah. Well, in that case, yes that's what I did. I added it to index.template.php.

Arantor

So you should move it from the 'shown on every page' template to the 'shown on the list of boards' template like I mentioned.
Holder of controversial views, all of which my own.


bahgheera

So there's no way to use the $context variable or another variable to check which page I'm on?

Arantor

I'm telling you that you don't need to.
Holder of controversial views, all of which my own.


bahgheera

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.

Arantor

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.
Holder of controversial views, all of which my own.


bahgheera

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.

Burke ♞ Knight

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!

Arantor

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.)
Holder of controversial views, all of which my own.


bahgheera


bahgheera

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?

Advertisement: