Forum for discussing general topics related to Couch.
2 posts Page 1 of 1
I have menu.php in /snippets folder and include it using
Code: Select all
<cms:embed 'menu.php' />  


At the top of each site page I have
Code: Select all
<?php $currentPage = 'home'; ?>


And in menu,php i have my menu shown as
Code: Select all
<li class="<?php if($currentPage =='home'){echo 'active';}?>"><a href="index.php">Home</a></li>


The active class works if menu.php is in the code for each page but not if I embed it as above
Any ideas?
(Hope i explained that ok!)
Thanks
To execute PHP within snippets, we need to use <cms:php> tags.

Please try changing your original code from this -
Code: Select all
<li class="<?php if($currentPage =='home'){echo 'active';}?>"><a href="index.php">Home</a></li>

to this -
Code: Select all
<li class="<cms:php> global $currentPage; if($currentPage =='home'){echo 'active';}</cms:php>"><a href="index.php">Home</a></li>

The modified code mainly consists of substituting the opening and closing PHP identifiers i.e. <?php and ?> with the equivalent Couch tags <cms:php> and </cms:php>.

Please do note, however, that any PHP variable defined outside the <cms:php></cms:php> block (e.g. the $currentPage variable in this case) needs to declared as global.

Hope it helps.
2 posts Page 1 of 1

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 3 guests