Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Smarty syntax in default.master.tpl = Something has gone wrong

ShmizzleShmizzle New
edited December 2014 in Vanilla 2.0 - 2.8

I'm in the process of updating to 2.1 and in my theme I've got some Smarty code that looks like this:

{if strncmp($smarty.server.REQUEST_URI, "/discussion/", 12) != 0}

(that line is in the file about 4 times)

When these lines are in the file I get a big X-eyed "smiley" face page that says "something has gone wrong". Debugging enabled shows no further information. When I remove the lines, the page loads fine (although it looks messed up because it's a 2.0 theme).

Any ideas? I tried setting permissions to 777 for the cache folder but that didn't change anything.

Comments

  • it looks like you are checking for the discussion controller and trying to use php or something.
    I think that falls within bad practices as far as theme is concerned.

    you might change it to

    {if $BodyID !='vanilla_discussion_index'}
    
    and see if that helps.
    
    or try
    
    {if $BodyID =='vanilla_discussion_index'}
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • if you still have issues....

    what theme?

    and post the .tpl

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Well I was trying it with public_vforg. However I tried your modified syntax in the Bootstrap theme and it works well. Thanks!

  • Any ideas? I tried setting permissions to 777 for the cache folder but that didn't change anything.

    Why would this change anything? Shotgun debugging is never a good strategy.

    If you can, never set any folder to 777. If you are able to set users and groups then there absolutely no need for such ridiculous permissions, unfortunately cheap webhost promote bad practice then people don't really learn how to mange their server. But is has nothing to do with this issue.

    Back to to question. What is it you are try it do? It might be this is the wrong place for the logic. Let us know the objective.

    Also if it the right place for the logic it is still the wrong logic. You have to work with the framework rather than regardless of it. So low level stuff like REQUEST_URI is unlikely what you want to use.

    Lastly smarty isn't php, so if you are using php syntax it obvious isn't going to work. You need to read the documentation for smarty and be aware that you have a limited subset of smarty to work with. if you want to use php you will need to create a smarty function

    Any developer has a learning curve, they have to be able to debug their own stuff, and find a certain amount out themselves.

    grep is your friend.

  • @x00 said:
    Why would this change anything? Shotgun debugging is never a good strategy.

    Doesn't smarty cache some files in the cache directory? I did some Googling while trying to figure out the issue and I found a topic or two where someone had an issue with Smarty and I believe it was suggested they check the permissions. The 777 permission was just temporary to make sure that wasn't the issue.

    @x00 said:
    Back to to question. What is it you are try it do? It might be this is the wrong place for the logic. Let us know the objective.

    I used Smarty in the main theme .tpl file to prevent the side bar from being displayed if the user is viewing a discussion, and also to change a few style properties of a couple of the main div id's based on that (e.g. making the width of the discussion fill the whole page instead of just the right side). Fortunately, peregrine's code works just as well, as does the new theme I'm using now.

    For a couple years I was using javascript to accomplish the same goal but being javascript it had the annoying side effect of not kicking in right away, resulting in you seeing the sidebar for a brief moment, with the discussion on the right hand of the page, and then the sidebar would disappear and the discussion would take up the rest of the width. Then I discovered the existence of Smarty.

    As I was typing this post I just realized that I think what might have been happening with my code is that I never re-added strncmp as an allowable function in the security_settings/IF_FUNCS array in Smarty.class.php, after I'm sure it got overwritten when I upgraded to 2.1.

  • As I was typing this post I just realized that I think what might have been happening with my code is that I never re-added strncmp as an allowable function in the security_settings/IF_FUNCS array in Smarty.class.php, after I'm sure it got overwritten when I upgraded to 2.1.

    another reason not to modify core :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I used Smarty in the main theme .tpl file to prevent the side bar from being displayed if the user is viewing a discussion

    You can achieve this in other ways. Either with css or themehooks.

    As I was typing this post I just realized that I think what might have been happening with my code is that I never re-added strncmp as an allowable function in the security_settings/IF_FUNCS array in Smarty.class.php, after I'm sure it got overwritten when I upgraded to 2.1.

    Don't modify the core.

    grep is your friend.

Sign In or Register to comment.