Jump to content

if condition


tekno
 Share

Recommended Posts

hi i use if condition for $page->template=='templatename' but after 2. if condition codes get error

codes are the same but when i add 2. condition gets an error "syntax error, unexpected end of file"

<?php //gallery lightbox css
if ($page->template=='photos'){?>
	<link rel="stylesheet" href="<?=$config->urls->templates;?>assets/css/lightbox.css">
<?php} ?>

this works fine

but

<?php //gallery lightbox css
if ($page->template=='photos'){?>
	<link rel="stylesheet" href="<?=$config->urls->templates;?>assets/css/lightbox.css">
<?php} ?>	
. . . . .. . . . . .. . . . .. . .
. . . . .. . . . . . . .. . . . ..
<?php //products calendar css
if ($page->template=='products'){?>
	<link rel="stylesheet" href="<?=$config->urls->templates;?>assets/css/calendar.css">
<?php} ?>

whats wrong? 2.condition for same operator ($page->template) using different?

Link to comment
Share on other sites

thanks K07N its not giving error with this codes

<?php if ($page->template=='products'): ?>
    <link rel="stylesheet" href="<?=$config->urls->templates;?>assets/css/calendar.css">
<?php endif; ?>

but its not work too

i want to add some extra metas into included _header.php why didnt i succeed? or how its easier to include?

Link to comment
Share on other sites

$page->template returns the template object, wish is not equal to the string 'products'. Try this instead:

if ($page->template->name == 'products')

That's wrong. The template object does have a __toString() method, which returns the name, therefore comparing without type check does work.

// For a page using a template named "products"
$page->template == "products"        // true
$page->template === "products"       // false (object !== string)
$page->template->name === "products" // true (string === string)
  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...