Uutiset:

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

Main Menu
Advertisement:

Help with proper writing of html to php

Aloittaja Gargoyle, marraskuu 16, 2013, 12:34:40 IP

« edellinen - seuraava »

Gargoyle

I have this piece of html code...

<li><a href="#" onclick="setActiveStyleSheet('default'); return false;">Default</a></li>

But when I place it into my index_template file my editor tells me it isn't proper syntax. Not sure what I need to do to fix it.

Any help would be great!!

I'm going back to see if I can find something I can mimic the syntax of.

far2slow

have you tried to escape the single quotes

(\'default\')


Gargoyle

I'll attach a screen shot of what it wants.. Just not sure "where" to put it...

emanuele

Maybe showing just half of the line would make it a bit harder to guess for a bigger reward :P


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Gargoyle

Thats the entire line. Your sarcasm and total lack of help is duly noted.

Arantor

The sarcasm was making the completely valid point that the line on its own gives us absolutely no context to work with.
Holder of controversial views, all of which my own.


Gargoyle

Lainaus käyttäjältä: far2slow - marraskuu 16, 2013, 12:43:47 IP
have you tried to escape the single quotes

(\'default\')

Ah great!!!  I did it wrong the first time!  This works great!

Thanks a bunch!

Gargoyle

Lainaus käyttäjältä: Arantor - marraskuu 16, 2013, 01:23:55 IP
The sarcasm was making the completely valid point that the line on its own gives us absolutely no context to work with.

Being as that particular line was at fault I didn't know that surrounding code would be needed to see what was wrong in that one line. Your response of needing surrounding code was actually helpful. Where the previous was just meant to be a jerk.

Arantor

You'd be surprised how often 'a particular line seems to be at fault' when the real fault is a considerable distance away.

Actually, emanuele was making the exact same point, just far more flippantly than I would.
Holder of controversial views, all of which my own.


Gargoyle

Understood and I appreciate the clarification. In the future I will include the surrounding code as well.

emanuele

Lainaus käyttäjältä: Gargoyle - marraskuu 16, 2013, 01:20:37 IP
Thats the entire line. Your sarcasm and total lack of help is duly noted.
<?php
echo 'something' 
<
li><a href="#" onclick="setActiveStyleSheet('default'); return false;">Default</a></li>


<?php
echo 'something
<li><a href="#" onclick="setActiveStyleSheet('
default'); return false;">Default</a></li>


<?php
echo 'something'
<li><a href="#" onclick="setActiveStyleSheet('default'); return false;">Default</a></li>


<?php
<li><a href="#" onclick="setActiveStyleSheet('default'); return false;">Default</a></li>
echo 
'something'


All these variants would give a parser error, all for slightly different reasons, but always on the line you posted.
All of them have different solutions.

So, the fact a possible answer was already posted and you answered posting again the error message, made me think you already tried the proposed fix and it didn't work, so the only other obvious thing was asking for more information.

Well, apparently you posted your second message just because it was ready and not as answer to far2slow... heh :P


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Gargoyle

Honestly I didn't expect escaping the single quotes to work. I tried it but I did it wrong when I did. During that time I was playing with my code editor. (Komodo) and it was giving me the parse error from the beginning but I had just seen the "suggestions" or what it expected so I posted that.

Thinking that since I "added" the line of code that was giving the parse error I just assumed it had to be something to do with the syntax since it was copied from an HTML sheet and I was trying to make it work inside php tags. I've run into that before but can normally find an "example" of what I am trying to do with SMF's base code.

I haven't seen very many escape tags used in SMF's base code so I figured it had to be something else. Since Komodo was suggesting one thing and the posted fix was suggesting another I wasn't totally sure which way to go or which way would be "best" to go.

In any event here is the chunk of code I have that is working at the moment.

if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
echo '
<li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';

echo '
<li>', $context['current_time'], '</li>
<li><a href="#" onclick="setActiveStyleSheet(\'default\'); return false;">Mustang</a></li>
<li><a href="#" onclick="setActiveStyleSheet(\'alternate 1\'); return false;">Green Swirls</a></li>
<li><a href="#" onclick="setActiveStyleSheet(\'alternate 2\'); return false;">Country Road</a></li>
<li><a href="#" onclick="setActiveStyleSheet(\'alternate 4\'); return false;">Giant Snowman</a></li>
<li><a href="#" onclick="setActiveStyleSheet(\'alternate 5\'); return false;">Angry Weed</a></li>
</ul>';
}


Long story short it swaps out the "default" css file for different ones based on the users choice of what they would like the current theme to look like. It uses a bit of java script as well and all of the "alternate" style sheets are listed with the default one.

I still want to change all of this into a drop down menu. Select box to be more precise but I wanted to get the basics of it working first and these links were a bit of a hurdle for me as the rest came pretty easy.

I am not a coder so I am not very confident when asking questions like this as I really don't know enough to even know what I should, or should not be saying to accurately describe the issue I am having.

At this point escaping the single quotes is working. When I try to implement a select box who knows. But I at least know that the javascript is loading, the css files are loading, and the links are good. So I know it can work in its current configuration.

Once again thanks for the help I and will try to include more detailed info in the future.

far2slow

Always worth posting more info that you think is needed, emanuele and Arantor or two of the most knowledgeable people here on smf and they will always to there best to help.  if you can give them the information that they need, my responce was just a stab in the dark what your problem was and as emanuele pointed out there could be many reasons why it did not work, if you give these guys more info then they will be able to tell you what the problem is with out sending you down the wrong path.

Advertisement: