I'm setting up an articlescript based site, and need to add code to differentiate the home page from all the others. Can someone please help me out with some code to add? I figured it would be something like this but it doesnt work. {if $page eq '$smarty.const.DOC_ROOT'}test text{/if} Code (markup):
the format of if statement should be like this if(statement){ statement } I am not sure with this but you can try it... if($HTTP_SERVER_VARS['DOC_ROOT']=="index.php"){ echo "home"; }else{ echo "other files"; } Code (markup): But for sure you can play on it.
This is in a Smarty template, right? I don't know Smarty, but I do know that it's not the same as normal PHP. What if you just tried: {if $page eq $smarty.const.DOC_ROOT}test text{/if} That is, without the single quotes?
OK: so just to be sure, you are doing this in a Smarty template, right? If it's just normal PHP, then it's going to be something totally different...
Right. It is a smarty type deal. ere is some {if} code that is already present on the file. {if $page eq 'article'}{$article[0]} {elseif $page eq 'articles'}{$title} {elseif $page eq 'last'}Last Articles {elseif $page eq 'searchresult'}{$title} {/if} Code (markup):
Well, I guess the first thing to do is to dump the two variables on screen, just to see what value Smarty thinks they are... Just before your if, try something like: page value is: {$page}<br> smarty.const.DOC_ROOT value is: {$smarty.const.DOC_ROOT}<br> Code (markup): So at least now you can visually confirm that they are or are not the same... Does that make sense?
OK, Here is the code exactly as I put it in the file: page value is: {$page}<br> smarty.const.DOC_ROOT value is: {$smarty.const.DOC_ROOT}<br> {if $page eq $smarty.const.DOC_ROOT}test text{/if} {if $page eq 'article'}{$article[0]} {elseif $page eq 'articles'}{$title} {elseif $page eq 'last'}Last Articles {elseif $page eq 'searchresult'}{$title} {/if} Code (markup): This is what showed on every page, not just the main: page value is: last smarty.const.DOC_ROOT value is: Last Articles Code (markup):
OK, I think I found a way around it. By default, the home page is the "last articles" so this is what I used and seems to work: {if $page eq last}test text{/if} Code (markup):
If that works, then congrats. The actual problem, though, is that $smarty.const.DOC_ROOT is not being initialised at all. Unfortunately, I don't know Smarty enough to know why, but that seems to be the problem, anyway.