Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Vanilla 2.3 fully supports PHP 7. Get it now!
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

[Solved] Template conditionals to only show something on a particular page?

I'd like to know the conditional code that I can put into default.master.tpl to only show it on the homepage?

Best Answer

  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓
    In smarty you wrap conditionals in between {if}..{/if} tags.

    You can use one of two variables we pass in to determine which page you are on:
    {if $Path == ''}...{/if}
    or
    {if $BodyID == 'vanilla_discussions_index'}...{/if}
    $Path Shows the path the user entered in the browser. $BodyID maps to the application_controller_method being called. If you don't know what to compare to you can just output the variables in default.master.tpl and browse around your applicaiton like this:
    BodyID: {$BodyID}, Path: {$Path}
    You can also see all of the data available to you with the {debug} tag. This will launch a popup so you may have to unblock it in your browser.

    You can find the full documentation for the {if} tag here.
    JoZ3_69

Answers

  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓
    In smarty you wrap conditionals in between {if}..{/if} tags.

    You can use one of two variables we pass in to determine which page you are on:
    {if $Path == ''}...{/if}
    or
    {if $BodyID == 'vanilla_discussions_index'}...{/if}
    $Path Shows the path the user entered in the browser. $BodyID maps to the application_controller_method being called. If you don't know what to compare to you can just output the variables in default.master.tpl and browse around your applicaiton like this:
    BodyID: {$BodyID}, Path: {$Path}
    You can also see all of the data available to you with the {debug} tag. This will launch a popup so you may have to unblock it in your browser.

    You can find the full documentation for the {if} tag here.
    JoZ3_69
  • @Todd Thank you very much!!!!

Sign In or Register to comment.