ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP in template embed not working as expected

September 13, 2011 10:28am

Subscribe [2]
  • #1 / Sep 13, 2011 10:28am

    JamesBrighton

    146 posts

    I have the following code in my template which adds the class of ‘current’ to the current page:

    {if {category_id} == '<?php echo $cat_id ?>'}
        <li class="current"><a href="/{segment_1}/?cat_id={category_id}">{category_name}</a></li>
    
    {if:else}
        <li><a href="/{segment_1}/?cat_id={category_id}">{category_name}</a></li>
    {/if}

    Im maintaining this site but I didn’t build it. Ive modified the site and I need to use this code in a few different places, so ive put it in a template embed. The links still work but the ‘current’ class is never added. Thanks

  • #2 / Sep 13, 2011 7:47pm

    Dan Decker

    7338 posts

    Hello James,

    Let’s see if we can get this sorted out. First, have you ensured that PHP is turned on for the embedded template? If you give a little more detail about what you are trying to achieve, we may be able to suggest ways you can do this strictly with ExpressionEngine tags.

    Cheers,

  • #3 / Sep 14, 2011 5:49am

    JamesBrighton

    146 posts

    This code is at the top of the page im moving the menu from, when I added it to the embed template it worked fine:

    <?php
        $this->EE =& get_instance();
        
        $cat_id = $this->EE->input->get('cat_id') ? $this->EE->input->get('cat_id') : '';
    ?>

    Thanks

  • #4 / Sep 15, 2011 12:21am

    Dan Decker

    7338 posts

    James,

    Just making sure, you are all set then?

    Is there anything else we can assist you with?

    Cheers,

  • #5 / Sep 15, 2011 5:40am

    JamesBrighton

    146 posts

    Yeah its working fine. Thanks

  • #6 / Sep 15, 2011 11:37pm

    Dan Decker

    7338 posts

    resolved

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases