Welcome Guest, Not a member yet? Register   Sign In
Template and dynamic classes
#1

[eluser]Radou[/eluser]
Hello everyone.

I am using a template with header.php, sidebar.php, main.php and footer.php
On the sidebar panel I have menus organized such as :

Code:
<ul>
<li class="active"> Test 1 </li>
<li> Test 2 </li>
<li> Test 3 </li>
</ul>

I don't want to load the sidebar everytime, but when I click on the menus I want them to change class to "Active" and remove that class from the first <li>

My question is actually devided on two :

1/ How can I change the class dynamically on click
2/ How to load the main view without loading the page (ajax ?)

Thank you
#2

[eluser]TheFuzzy0ne[/eluser]
By changing the class dynamically, do you mean on a new page request, or using Javascript?

Are you using jQuery or another Javascript library?

You can check to see if the request is an AJAX call, and send only your main template as required (without header, footer and side bar). CodeIgniter provides you with $this->input->is_ajax_request(), to check whether or not the incoming request is an AJAX request. Using that, you should be able to respond accordingly.

It's difficult to advise you with the small amount of code you posted. You've explained what you want to do, but it's difficult to understand the context in which you want to do it. It would help a lot more if we could see what the actual menu entries were, and as well as your view, and controller code.
#3

[eluser]Radou[/eluser]
Thank You ThFuzzyOne for your answer.

As for the Class, yes, I meant on a new page load. I know how to do it with javascript after some tests yesterday, but when the page reload I lose changes


As for the other request I did not yet develop the view and the controller I have just some draft code.Basically, I want the header, sidebar footer to be displayed only once with links to other views that will go on click on the sidebar to the main content of the page, all the views wil be displayed in the div labeled "main" for example.

Thanks again.
#4

[eluser]TheFuzzy0ne[/eluser]
Most apps use the URL to decide which menu entry to make active. I guess you could store the current active menu entry in a cookie, though, or since you're using AJAX, you could store it in the user's session. Since you're making a request for the content through AJAX anyway, it shouldn't be a problem for your controller to store the active menu entry when the request is made.
#5

[eluser]kostyak[/eluser]
Hi,Radou!
Answering on your questions, I can suggest you to use jQuery library for JS for both task:
>1/ How can I change the class dynamically on click
make function to remove class from the first <li> and put it to the appropriate <li>
>2/ How to load the main view without loading the page (ajax ?)
Make Ajax request through Jquery function load() and if success, than execute function from the first answer.




Theme © iAndrew 2016 - Forum software by © MyBB