Welcome Guest, Not a member yet? Register   Sign In
Hide/Show content on sidemenu
#1

[eluser]Kamy[/eluser]
Hi:

I have a pretty simple template that displays the data. It has a header, content, sidemenu and footer section.
The items in the sidemenu are the same throughout the website, ie facebook link, google ads, etc...

But now we want to display certain items on some pages only. For example we want google ads box to appear only on products page.
Or a jukebox to appear on albums page only (within the sidemenu).

How would I go about doing this?

Thanks
#2

[eluser]gvillavizar[/eluser]
Ok, out of my mind and with quick code, the most basic thing you can do is to define a parameter in each of the controller functions you want to display something.

Example:

In you controller define $data['is_jukebox'] = TRUE;

Then in your view do something like this:

Code:
<?php
if(isset($is_jukebox) && $jukebox):
// Display the jukebox code
endif;
?>

Might not be the best approach out there, but definitely will help you through.
#3

[eluser]TWP Marketing[/eluser]
You can pass an identifier for each unique 'page' of content. Use it to conditionally display your menu/sidebar content.

This could be set in each content view, since they are usually unique, but if your controller/function values are not unique, you may need one additional value to drive your menu/sidebar logic.

I know this is very general, but it depends on how your menu and forms passes values back to the controller, either as POSTed vars or as query string segments.

I use a var:
Code:
$pn = 'some_page_name'
which is passed as a hidden form field in my menu items. You can also pass it as a URL segment:
Code:
anchor("controller/method/".$pn,"Click Here")
if you're using html links and don't mind the user seeing the value.

There are other approaches. I'd like to hear from others on the forum about how they handle his...
#4

[eluser]kcmerrill[/eluser]
It's not great form, but if you're lazy like me, and it's just a simple template I use the CI_Router fetch_class() and fetch_method() so in your template it'd look something like this:

if($this->router->fetch_class() == "products"){
//display only on products page
}

Or if you wanted to go down to the next level, throw in fetch_method()

if($this->router->fetch_class() == "products" && $this->router->fetch_method() == "tshirts"){
//display only if it's a tshirts page ...
}

ect ...

-kc




Theme © iAndrew 2016 - Forum software by © MyBB