IF Statement for Specific Page

In 1.3.5, I was able to use an if statement like the following to add code in the head tag of certain pages . . . but this doesn’t seem to work in 2.0.12. Can someone let me know what I need to change to make this work in 2.0.12? I assume page.page_id is no longer valid. What is the new equivalent?


{if $page.page_id == 'service_manuals' or $page.page_id == 'owners_manuals'}Page Specific Code{/if}

$page.page_id is internal record number for the database. Maybe try $page.page which I think is the page name.



Bob

Use the actual page id:


{if $page.page_id == '23'}Page Specific Code{/if}

[quote name=‘jobosales’]$page.page_id is internal record number for the database. Maybe try $page.page which I think is the page name.



Bob[/QUOTE]



Thanks Bob, but so others know, this didn’t work.

[quote name=‘snorocket’]Use the actual page id:


{if $page.page_id == '23'}Page Specific Code{/if}[/QUOTE]



Where would I find the page_id number assigned to a certain page (like the home page)?

You can go edit the Page in Admin and check out the Preview link on the right to see the page_id number. You can also find it in your SQL tables but the Preview link is probably quicker. :slight_smile:

[quote name=‘scase’]You can go edit the Page in Admin and check out the Preview link on the right to see the page_id number. You can also find it in your SQL tables but the Preview link is probably quicker. :)[/QUOTE]



What about the home page? Which table would I find this in?

I don’t know…I’m not the best person to ask about some of these things as I’m still learning mySQL, Smarty templates and pHp. :slight_smile: I would think that the Home page isn’t given a number but you could just use the index.php as your identifier. I’m sure Sno will chime in with a better answer if there is one!

[quote name=‘scase’]I would think that the Home page isn’t given a number but you could just use the index.php as your identifier.[/QUOTE]

No, the index.php doesn’t work as this is not an id . . . this is the page name.

The page id option works fine for pages we can easily find the page id (like pages and products).



But how do we find the page id for pages like checkout, cart and the home page? Is there a db table to look this up or do these “special” pages operate differently?

I think it would then be:

{if $dispatch == 'checkout'}Page Specific Code{/if}

[quote name=‘snorocket’]I think it would then be:

{if $dispatch == 'checkout'}Page Specific Code{/if}[/QUOTE]



Unfortunately, that didn’t work, nor did checkout.checkout. And the home page would have to be something completely different since it doesn’t have a dispatch url.

Wouldn’t “blocks” need to use if statements since they are page specific. Maybe CS-Cart has already provided us the code somewhere related to blocks . . . I’m just not sure where to look.

[quote name=‘knoxbury’]Unfortunately, that didn’t work, nor did checkout.checkout. And the home page would have to be something completely different since it doesn’t have a dispatch url.[/QUOTE]

Try {if $controller == ‘checkout’ && $mode == ‘checkout’} for checkout. For the cart, {if $controller == ‘checkout’ && $mode == ‘cart’}



Bob

[quote name=‘knoxbury’]Unfortunately, that didn’t work, nor did checkout.checkout. And the home page would have to be something completely different since it doesn’t have a dispatch url.[/QUOTE]

Try {if $controller == ‘checkout’ && $mode == ‘checkout’} for checkout and {if $controller == ‘checkout’ && $mode == ‘cart’} for cart.



For the homepage, try either {if $controller == ‘index’} or {if $controller == ‘index’ && $mode == ‘index’}



Bob

[quote name=‘jobosales’]For the homepage, try

Try {if $controller == ‘checkout’ && $mode == ‘checkout’} for checkout. For the cart, try either {if $controller == ‘index’} or {if $controller == ‘index’ && $mode == ‘index’}



Bob[/QUOTE]



Bingo! Thanks! I was able to verify that this worked on the checkout page and the {if $controller == ‘index’} worked on the home page (I didn’t try the 2nd option). Thanks again, that helps!

how about block?

[quote name=‘vidan’]how about block?[/QUOTE]



I’m not sure I understand your question. Blocks are already managed on a page by page basis under the Design > Blocks section of the admin panel.