Jump to content

[SOLVED]custom template page name / check if viewing custom template


sixthmind

Recommended Posts

I have created a custom template and now I need to check if the page we are viewing is using that template and do something if it is.

I understand we have global variable $page_name

In header.tpl and I can currently use:

{if $page_name == 'index'}
{if $page_name == 'cms'}

 

How would I do something like: if $page_name = 'custom-template' ?

or anything alternative which would check the current page so I can then do something if on that page.

 

I found $smarty.template, but if put in header.tpl, the template it shows is header.tpl of course.

 

Any suggestion how to solve this problem? Your help would be really appreciated.

Link to comment
Share on other sites

Hello,

 

Doesn't

{if $page_name == 'custom-template'}

 

work?

 

It should work,provided that you created the page well.

 

1. Create a php file at root. (eg custom-template.php)

2.Point the custom-template.php to a newly created controller in folder controllers (eg customTemplateController.php)

3. The controller then uses function displayContent() to redirect to your custom-template.tpl

 

In the customTemplateController.php,

 

add this line : public $php_self = 'custom-template.php';

 

Then you will surely be able to use $page_name == 'custom-template'.

 

Hope this helps.

  • Like 1
Link to comment
Share on other sites

  • 7 months later...
  • 2 months later...
  • 5 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...