Results 1 to 5 of 5

Thread: Catalog Template Help (SOLVED)

  1. #1
    User
    Join Date
    07-20-09.
    Location
    Middlesbrough - United Kingdom
    Posts
    95

    Default Catalog Template Help (SOLVED)

    im trying to tell my template that if the page that is open is equal to the link in the catalog entry (<?php echo $entry['data']['link']['value']; ?>) then to add the word active to the css class, i have put the code i am using below, this at the moment does not work. could someone please help or point me in the right direction.

    Code:
    <?php if ($entry['{{env::page_alias}}']): ?>
    <li class="<?php echo $entry['data']['class']['value']; ?>Active"><a href="<?php echo $entry['data']['link']['value']; ?>" title="<?php echo $entry['data']['name']['value']; ?>">
    
    <?php echo $entry['data']['name']['value']; ?></p></a>
    <?php else: ?>
    <li class="<?php echo $entry['data']['class']['value']; ?>"><a href="<?php echo $entry['data']['link']['value']; ?>" title="<?php echo $entry['data']['name']['value']; ?>">
    
    <?php echo $entry['data']['name']['value']; ?></p></a>
    <?php endif; ?>
    I am pretty sure its the first line of my code that is incorrect im just not sure what it should be.

    Code:
    <?php if ($entry['{{env::page_alias}}']): ?>
    Thanks,
    Ste

  2. #2
    User
    Join Date
    06-29-09.
    Posts
    271

    Default Re: Catalog Template Help

    Code:
    <?php if ($entry['{{env::page_alias}}']): ?>
    Two remarks;
    1: The php gets evaluated first, so {{envage_alias}} will be seen as exactly that string and not be replaced first with 'home', 'contact', 'catalog' or whatever.
    2: You test for the value of $entry['home'/'whatever']. I doubt that variable will ever exist.

    Solution;
    Compare $entry['data']['link']['value'] to something php can access. Now I'm not sure if this is a good idea or not, but the alias can be found at several places, one being here: $GLOBALS[objPage]->alias. That means the line should become:

    Code:
    <?php if ($entry['data']['link']['value'] == $GLOBALS[objPage]->alias): ?>
    <li class="<?php echo $entry['data']['class']['value']; ?>Active"><a href="<?php echo $entry['data']['link']['value']; ?>" title="<?php echo $entry['data']['name']['value']; ?>">
    
    <?php echo $entry['data']['name']['value']; ?></p></a>
    <?php else: ?>
    <li class="<?php echo $entry['data']['class']['value']; ?>"><a href="<?php echo $entry['data']['link']['value']; ?>" title="<?php echo $entry['data']['name']['value']; ?>">
    
    <?php echo $entry['data']['name']['value']; ?></p></a>
    <?php endif; ?>
    But wait! That is immensely inefficient or at the very least hard to maintain. There are several ways to do it better, I'll choose the easiest to understand.

    You have the entire menu entry part coded in twice just to get in the class Active. Why not always put in the variable $addClass and assign it either with Active or nothing? The code would become:
    Code:
    <?php
    $addClass = '';
    if ($entry['data']['link']['value'] == $GLOBALS[objPage]->alias) {
      $addClass = 'Active';
    }
     ?>
    <li class="<?php echo $entry['data']['class']['value']; ?><?php echo $addClass; ?>"><a href="<?php echo $entry['data']['link']['value']; ?>" title="<?php echo $entry['data']['name']['value']; ?>">
    
    <?php echo $entry['data']['name']['value']; ?></p></a>
    That should do it :P There may be some errors in my code, but the idea should be clear. This last piece of code is easier to maintain if you need to change it.

  3. #3
    User
    Join Date
    07-20-09.
    Location
    Middlesbrough - United Kingdom
    Posts
    95

    Default Re: Catalog Template Help

    Hey thanks for your reply.

    I dont know any php which is way my template code was not so good, lol.

    I see what you mean about the way in which i had written the code though, using the add class is much easier.

    The only problem is that this still does not work, im pretty sure its this part

    Code:
    $GLOBALS[objPage]->alias
    is there a way that i can print out the options of $GLOBALS?

    Thanks,
    Ste

  4. #4
    User
    Join Date
    07-20-09.
    Location
    Middlesbrough - United Kingdom
    Posts
    95

    Default Re: Catalog Template Help

    I also notice that you said it was not a good idea to match the alias to the make the css change to Active, would it be better to match it too the body class?

    if so how would i do this? I have pasted my template code below.
    Code:
    <?php if (count($this->entries)): ?>
    <?php
    $addClass = '';
    if ($entry['data']['link']['value'] == $GLOBALS[objPage]->alias) {
      $addClass = 'Active';
    }
    ?>
    <div id="navRowContainer">
    <ul>
    <?php foreach ($this->entries as $entry): ?>
    <li class="<?php echo $entry['data']['class']['value']; ?><?php echo $addClass; ?>">"><span><?php echo $entry['data']['name']['value']; ?></span>
    <?php endforeach; ?>[/list]
    <?php else: ?>
    
    <?php if ($this->condition): ?>
    <div class="condition"><?php echo $this->condition; ?></div>
    <?php else: ?>
    <p class="info">There are no entries matching your search.</p>
    <?php endif; ?>
    <?php endif; ?>
    </div>
    I hope someone can help with this im really stuck atm.
    Thanks, Ste

  5. #5
    User
    Join Date
    07-20-09.
    Location
    Middlesbrough - United Kingdom
    Posts
    95

    Default Catalog Template Help *SOLVED*

    All problems solved

    In the end I matched the class of the link in my catalog (specified using a taxonomy)to the class of the page in the site structure then used veras code to add an "Active" to the class name. This means that child pages can also have the active state if the correct CSS class is applied.

    Below is my template code for making custom navigation with active and hover states.

    Code:
    <?php if (count($this->entries)): ?>
    <div id="navRowContainer">
    <ul>
    <?php foreach ($this->entries as $entry): ?>
    <?php
    $addClass = '';
    if ($entry['data']['class']['value'] == $GLOBALS[objPage]->cssClass) {
    $addClass = 'Active';
    }
    ?>
    <li class="<?php echo $entry['data']['class']['value']; ?><?php echo $addClass; ?>">"><span><?php echo $entry['data']['name']['value']; ?></span>
    <?php endforeach; ?>[/list]
    <?php else: ?>
    
    <?php if ($this->condition): ?>
    <div class="condition"><?php echo $this->condition; ?></div>
    <?php else: ?>
    <p class="info">There are no entries matching your search.</p>
    <?php endif; ?>
    <?php endif; ?>
    </div>
    Thanks to vera who put me on the right lines.
    Ste

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •