Jump to content

Recommended Posts

Posted

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?

Posted

Perhaps you got an unclosed condition/loop elsewhere in your code, or the file was uploaded only partly. I see no syntax error in the chunk above.

Posted

Just insert space after php:

<?php } ?>

And I think it is good to use alt syntax in your examle, it is easier to read:

<?php if (condition): ?>
  <div>bla-bla-bla</div>
<?php endif; ?>
Posted

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?

Posted

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

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

$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
Posted

ahh sorry codes working but im searching printed codes on wrong place :)

thanks guys

btw

 if (condition):

//do

elseif (condition):

//do another

endif;

usage is really easier thanks

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
  • Recently Browsing   0 members

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