I'm running a magento custom template on magento community edition 1.7. How do I hide $custom_tab3 from guests? I want that tab to only show up for logged in users. Please see code below. Any help is super highly appreciated!
<ul id="nav">
<?php if (Mage::getStoreConfig('celebritysettings/celebritysettings_header/navigation_home')): ?>
<li class="level0 level-top">
<span><?php echo $this->__('How It Works'); ?></span>
</li>
<?php endif; ?>
<?php
echo $_menu;
$custom_tab = Mage::getModel('cms/block')->load('celebrity_navigation_block');
if($custom_tab->getIsActive()) {
echo '
<li class="level0 level-top parent custom-block">
<a href="'.$this->getBaseUrl().'gift" class="level-top">
<span>'.$custom_tab->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block')->toHtml().'</div>
</li>';
}
$custom_tab2 = Mage::getModel('cms/block')->load('celebrity_navigation_block2');
if($custom_tab2->getIsActive()) {
echo '
<li class="level0 level-top parent custom-block" >
<a href="'.$this->getBaseUrl().'plans" class="level-top">
<span>'.$custom_tab2->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block2')->toHtml().'</div>
</li>';
}
$custom_tab3 = Mage::getModel('cms/block')->load('celebrity_navigation_block3');
if($custom_tab3->getIsActive()) {
echo '
<li class="level0 level-top parent custom-block">
<a href="'.$this->getBaseUrl().'showroom" class="level-top">
<span>'.$custom_tab3->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block3')->toHtml().'</div>
</li>';
}
$custom_tab4 = Mage::getModel('cms/block')->load('celebrity_navigation_block4');
if($custom_tab4->getIsActive()) {
echo '
<li class="level0 level-top parent custom-block">
<a href="'.$this->getBaseUrl().'magazine" class="level-top">
<span>'.$custom_tab4->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block4')->toHtml().'</div>
</li>';
}
?>
</ul>
You can use Mage::getSingleton('customer/session')->isLoggedIn() to check whether the current user is logged in. In your code you can use it like this:
$custom_tab3 = Mage::getModel('cms/block')->load('celebrity_navigation_block3');
if($custom_tab3->getIsActive() && Mage::getSingleton('customer/session')->isLoggedIn()) {
echo '
<li class="level0 level-top parent custom-block">
<a href="'.$this->getBaseUrl().'showroom" class="level-top">
<span>'.$custom_tab3->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block3')->toHtml().'</div>
</li>';
}
or even
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$custom_tab3 = Mage::getModel('cms/block')->load('celebrity_navigation_block3');
if($custom_tab3->getIsActive()) {
echo '
<li class="level0 level-top parent custom-block">
<a href="'.$this->getBaseUrl().'showroom" class="level-top">
<span>'.$custom_tab3->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block3')->toHtml().'</div>
</li>';
}
}
to prevent unnecessary retrieval of the cms/block model.
Related
I need to put session on the same page sidebar. when user click on any button session will get for that tab. like
Search Job
Customers
etc
In the sidebar the button or not link with any page. i am creating a dialogue box for each so their is no page for the links that's why i am facing the problem. when user click any of the sidebar button the name should highlight.
DashboardController
public function disp()
{
Session::put('page', 'search-job');
Session::put('page', 'customer');
return view('front.disp');
}
layout.blade.php
#if(Session::get('page')=="search-job")
<?php $active = "active"; ?>
#else
<?php $active = ""; ?>
#endif
<li class="nav-item {{$active}}">
<a href="javascript:void(0)" class="nav-link nav-toggle">
<span class="title">SEARCH JOBS</span>
</a>
</li>
#if(Session::get('page')=="customer")
<?php $active = "active"; ?>
#else
<?php $active = ""; ?>
#endif
<li class="nav-item {{$active}}">
<a href="javascript:void(0)" class="nav-link nav-toggle">
<span class="title">Customer</span>
</a>
</li>
How to handle on this sidebar
Thanks!
as i understand from the comments you want to have different active sessions then you have 2 options like below:
put them in different indexes like this:
Session::put('page-search-job', true);
Session::put('page-customer', false);
and in view check them like this:
<li class="nav-item {{ Session::get('page-search-job') == true ? 'active' : '' }}">
<a href="javascript:void(0)" class="nav-link nav-toggle">
<span class="title">SEARCH JOBS</span>
</a>
</li>
put it in an array like this:
Session::put('page', [
"search-job"=>true,
"customer"=>false
]);
and in view check them like this:
<li class="nav-item {{ Session::get('page')['search-job'] == true ? 'active' : '' }}">
<a href="javascript:void(0)" class="nav-link nav-toggle">
<span class="title">SEARCH JOBS</span>
</a>
</li>
My flash data messages are not getting passed after a redirect in Codeigniter. I have a User controller:
class User extends CI_Controller {
public function register(){
$data['title']='Register Here';
$this->form_validation->set_rules('name' , 'Name' , 'trim|required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('user_name' , 'Username' , 'trim|required|max_length[32]|callback_check_username_exists'); // or is_unique[users.username]
$this->form_validation->set_rules('password', 'Password','trim|required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('confirm_password', 'Confirm Password','trim|required|min_length[5]|max_length[12]|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]', array('is_unique'=>'Email Already Used'));
if ($this->form_validation->run()==FALSE){
$this->load->view('templates/header');
$this->load->view('users/register',$data);
$this->load->view('templates/footer');
} else {
$option=array('cost'=>12);
$encrypt_password=password_hash($this->input->post('password'),PASSWORD_BCRYPT,$option);
$this->user_model->add_user($encrypt_password);
$this->session->set_flashdata('user_registered','You are Successfully Registered and Logged In');
// This works print_r($this->session->flashdata('user_registered'));
redirect('posts');
}
}
In the User controller flashdata 'user_registered ' is getting stored when I echo it as in comment above .
My POST controller is :
class Posts extends CI_Controller {
public function index(){
$data['title']='Latest Posts';
$posts=$this->post_model->get_post();
$data['posts']=$posts;
$this->load->view('templates/header');
$this->load->view('posts/index',$data);
$this->load->view('templates/footer');
}
My header view is :
<html>
<head>
<title>My Blog </title>
<link rel="stylesheet" href="<?php echo base_url();?>asset/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>asset/css/style.css">
<script src="https://cdn.ckeditor.com/4.11.1/standard/ckeditor.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="<?php echo base_url();?>">Bloggy</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor02" aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarColor02">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="<?php echo base_url();?>">Home </a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url();?>posts">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url();?>category">Categories</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url();?>about">About</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url();?>user/register">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url();?>posts/create">Create Post</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo base_url();?>category/create">Create Category</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<!-- Flash Data -->
<?php if($this->session->flashdata('user_registered')): ?>
<?php echo $this->session->flashdata('user_registered');?>
<?php else :?>
<?php echo ' no value '; ?>
<?php /*echo '<p class="alert alert-success">'.$this->session->flashdata('user_registered').'</p>'; */?>
<?php endif; ?>
In the header view the flashdata user_registered is showing up with no value. There is only one redirect and I should be able to access the flash data.
On further investigation I found my sessions are not working at all. I have auto loaded the sessions library and in the browser I am seeing ci_session as a cookie but I tested out both userdata and flashdata are not working after redirect. Flash data should work after for one redirect as I have been doing this for a long time. My previous application which worked perfectly is also failing because sessions are not getting stored.
I created a test code like below:
class User extends CI_Controller {
public function index (){
$sex='M';
$data1['user']=$this->user_model->get_all_users($sex);
$this->session->set_userdata('test','data');
$this->session->set_flashdata('flash', 'data');
print_r($_SESSION); exit();
redirect('projects');
}
I get Array ( [__ci_last_regenerate] => 1547034241 [test] => data [flash] => data [__ci_vars] => Array ( [flash] => new ) ) .
Now I echo the session in my projects controller :
<?php
class Projects extends CI_Controller {
public function index()
{
print_r($_SESSION); exit();
$result= $this->project->get_projects();
$data['result']=$result ;
$this->load->view('pages/projects',$data);
}
}
I just get this : Array ( [__ci_last_regenerate] => 1547034384 ) .
My config.php is $config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
flash data is session which will available at page only.. when it get freshh request on server it empty flash dat ... i.e your redirect unset the flash data... set user_data to get your message ... and unset it when you have it like
$this->session->userdata('user_registered','You are Successfully Registered and Logged In');
unset it at view
<?php
if($this->session->userdata('user_registered')){
echo $this->session->userdata('user_registered');
$this->session->unset_userdata('user_registered');
}
?>
I have this code in template to make a static home button. On the home button on hover over I would like to have a blog button underneath.
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<div class="container_24">
<div class="grid_24">
<div id="menu-icon">Categories</div>
<ul id="nav" class="sf-menu">
<li class="level0 level-top<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()) echo ' active'; ?>">
<a class="level-top" href="<?php echo $this->getUrl('')?>">
<span>Home</span>
</a>
</li>
<?php echo $_menu ?>
</ul>
</div>
<div class="clear"></div>
</div>
</div>
<?php endif ?>
basicly magento generate menu html:
<ul id="nav">
<li class="level0 nav-1 first level-top">
<span>Home</span>
</li>
<li class="level0 nav-1 first level-top parent">
<span>Category</span>
<ul class="level0">
<li class="level1 nav-2-1 first">
<span>Sub Category</span>
</li>
<li class="level1 nav-2-1">
<span>Sub Category</span>
</li>
<li class="level1 nav-2-1 last">
<span>Sub Category</span>
</li>
</ul>
</li>
</ul>
now, i want custom change output html menu (add more class html, add more element html...) somebody can help me?
There's different tutorials for doing this, but here's what I did:
Save /app/code/frontend/design/default/default/template/page/html/topmenu.phtml to /app/code/frontend/design/yourpackagename/yourthemename/template/page/html/topmenu.phtml and edit as follows:
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<li class="level0 nav-1 first level-top"><a href="/" class="level-top" ><span>Home</span></a></li>
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
To get yourpackagename and yourthemename, use System - Configuration - Design
hth, sconnie
I have the following in my header:
<div id="wrapper" class="homepage itemlist com_k2 category">
<div id="rt-header">
<div class="rt-container">
<div class="rt-grid-3 rt-alpha">
<div class="rt-block"></div>
</div>
<div class="rt-grid-9 rt-omega">
<div class="rt-fusionmenu">
<div class="nopill">
<div class="rt-menubar">
<ul class="menutop level1 ">
<li class="parent root f-main-parent firstItem f-mainparent-item"> <a class="daddy item bullet" href="www.domain.com"> <span> الرئيسية </span> </a> </li>
<li class="active root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
<li class="root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
<li class="root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
</ul>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
Now if you investigate the elements, you will find that there is an active flag in one of them. This makes sure that the currently seen page is highlighted in navigation bar. I want to know how can I change this based on view loaded? this is how I load views:
$this->load->view('layout/header');
$this->load->view('home');
$this->load->view('layout/footer');
So in this case the main navigation tab should be active.
Regards,
I completed something similar recently. Probably not the best way, but it works for me.
In your controller add this before your views
$data['contact'] = 'active';
Then pass the $data variable from the controller to the view
$this->load->view('header', $data);
And in your view add this to the list item
<li class="contact <?php if(isset($contact)) {echo $contact; }">
from the controller:
set names for your menus and put the loaded menu or page name in a variable as the following:
$data['active'] = 'menu1';
$this->load->view('layout/header',$data);
$this->load->view('home');
$this->load->view('layout/footer');
in the view:
<div id="wrapper" class="homepage itemlist com_k2 category">
<div id="rt-header">
<div class="rt-container">
<div class="rt-grid-3 rt-alpha">
<div class="rt-block"></div>
</div>
<div class="rt-grid-9 rt-omega">
<div class="rt-fusionmenu">
<div class="nopill">
<div class="rt-menubar">
<ul class="menutop level1 ">
<li class="<?php if(isset($active) && $active == 'menu1') echo 'active'; ?> parent root f-main-parent firstItem f-mainparent-item"> <a class="daddy item bullet" href="www.domain.com"> <span> الرئيسية </span> </a> </li>
<li class="<?php if(isset($active) && $active == 'menu2') echo 'active'; ?> root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
<li class="<?php if(isset($active) && $active == 'menu3') echo 'active'; ?> root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
<li class="<?php if(isset($active) && $active == 'menu4') echo 'active'; ?> root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
</ul>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
Give each menu item a distinct class or id then do it via jQuery or js
<li class="kitchen root"> <a class="orphan item bullet" href="load_kitchen_list"> <span> المطبخ </span> </a> </li>
<li class="anotherclass root"> <a class="orphan item bullet" href=""> <span style="font-size:medium;"> الملف الشخصي </span> </a> </li>
<li class="contact root"> <a class="orphan item bullet" href="main/contactus"> <span> للإتصال بنا</span> </a> </li>
Then for example in the contact page you'd simply do this via jQuery:
$(document).ready(function(){
$(".contact").addClass("active");
});