News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Simple If Else

Started by Low, April 18, 2015, 10:08:53 AM

Previous topic - Next topic

Low

Hi I'm trying to add some PHP to index.template.php but can't seem to get it to work or more than likely adding in the wrong spot.  I'm looking to add text if on the home page i.e. /index.php and else show a different text.

In the top_section of header I added this code: <?php if($url == '/index.php') { ?>
<span>test</span>
<?php } else{ ?>
<span>test 2</span>
<?php ?>

Colin

Hi Low,

It appears that you are using the variable $url before declaring it.

Please have a look here:

http://www.simplemachines.org/community/index.php?topic=518814.0
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Low

Ok thanks, I declared a $url variable in Boardindex and tried the code in TemplateIndex but I'm getting an error.

I'm learning PHP as fast as possible but at the moment I'm not sure where in templateindex this code can be pasted/inserted: <?php if($url == '/index.php') { ?>
<span>test</span>
<?php } else{ ?>
<span>test 2</span>
<?php ?>

Shambles

Are you putting all that inside an echo statement?

Low

Quote from: Shambles on April 18, 2015, 12:31:12 PM
Are you putting all that inside an echo statement?
I want the output span in the top_section in the header so not really sure where to place it but most places produce a parse error.

Shambles


Low

The code I posted is the code I have. Trying to paste it in somewhere on the index template.

Shambles

Well if you refuse to answer the question I cannot help you.

Low

Ok I'm sure there's someone who knows the solution.

Illori

Quote from: Low on April 19, 2015, 02:47:15 PM
Ok I'm sure there's someone who knows the solution.

i really doubt it as you are not giving the information required to give you a solution.

Low

I've gave the information I have.

Illori

then we can not answer you. you are not really telling us what you want to happen with this code or where you want it to go. i dont think the code as you have it will do much of anything as index.php is in all SMF urls.

Low

OK I understand you can't help.
Quote from: Illori on April 19, 2015, 03:41:16 PM
you are not really telling us what you want to happen with this code
Quote from: Low on April 18, 2015, 10:08:53 AM
I'm looking to add text if on the home page i.e. /index.php and else show a different text.
Try reading the OP.

Night09

Quote from: Low on April 19, 2015, 06:59:26 PM
OK I understand you can't help.
Quote from: Illori on April 19, 2015, 03:41:16 PM
you are not really telling us what you want to happen with this code
Quote from: Low on April 18, 2015, 10:08:53 AM
I'm looking to add text if on the home page i.e. /index.php and else show a different text.
Try reading the OP.

A cocky attitude like that will get you nowhere here....Id think about how your answering those only trying to offer you help out of their own free time. You dont like it post in [Paid] help and get someone to make it for a price..

Kindred

if you are using the code that you posted, then yes.. it will fail, completely and utterly - since it is NOT using the coding standards that SMF uses...

in more specific detail: SMF templates do not open and close php calls and then call html by itself.
SMF uses ALL php which mans that code is code and html needs to be echo'ed
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Low

Quote from: Night09 on April 19, 2015, 07:03:50 PM
Quote from: Low on April 19, 2015, 06:59:26 PM
OK I understand you can't help.
Quote from: Illori on April 19, 2015, 03:41:16 PM
you are not really telling us what you want to happen with this code
Quote from: Low on April 18, 2015, 10:08:53 AM
I'm looking to add text if on the home page i.e. /index.php and else show a different text.
Try reading the OP.

A cocky attitude like that will get you nowhere here....Id think about how your answering those only trying to offer you help out of their own free time. You dont like it post in [Paid] help and get someone to make it for a price..
Cocky? I've answered every question the best I can. In the ORIGINAL message I stated what I wanted to happen and where I was trying it. I'm NOT withholding information to be awkward, I simply don't know if it should be in an echo statement.

Low

Quote from: Kindred on April 19, 2015, 07:08:59 PM
if you are using the code that you posted, then yes.. it will fail, completely and utterly - since it is NOT using the coding standards that SMF uses...

in more specific detail: SMF templates do not open and close php calls and then call html by itself.
SMF uses ALL php which mans that code is code and html needs to be echo'ed
Thanks for your help, I don't think i have enough PHP knowledge and thought I'd get a simple "paste that code here" reply. I've managed to sort it out for now.

Kindred

#17
re reading the thread., you are also going about things all wrong.

you don't need an if/else...  just put the html to be displayed in boardindex.template.php inside an echo, since boardindex is the template that is displayed for the default/index.php view...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Night09

#18
Hey low you want to post abuse feel free.

Dont PM me like a coward, do it here in the thread ---------- where all can see your idiotic posts.

Edited by bigguy for language.

Bigguy

Hey...family friendly forum right...chill out.

Advertisement: