Hôm nay, blog xin giới thiệu nhúng highlight.js vào Blogger, Blogspot. Mục đích làm nổi bật các trình bài code lập trình trên Blogger
Bước 1: Nhúng code css and js của highlight
Các bạn có thể lấy links CDN tại đây:
//cloudflare links <link href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css" rel="stylesheet"></link> <script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
Bước 2: Các bạn đăng nhập vào quản trị Blog, sau đó Click chuột vào Chỉnh sửa HTML trong phần Trực tiếp trên Blog
Dán/Past mã code vào trước thẻ đóng </head>
Ví dụ minh họa hiển thị code lập trình PHP
public function create()
{
if(!in_array('createUser', $this->permission)) {
redirect('dashboard', 'refresh');
}
$this->form_validation->set_rules('groups', 'Group', 'required');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|is_unique[users.username]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[8]');
$this->form_validation->set_rules('cpassword', 'Confirm password', 'trim|required|matches[password]');
$this->form_validation->set_rules('fname', 'First name', 'trim|required');
if ($this->form_validation->run() == TRUE) {
// true case
$password = $this->password_hash($this->input->post('password'));
$data = array(
'username' => $this->input->post('username'),
'password' => $password,
'email' => $this->input->post('email'),
'firstname' => $this->input->post('fname'),
'lastname' => $this->input->post('lname'),
'phone' => $this->input->post('phone'),
'gender' => $this->input->post('gender'),
);
$create = $this->model_users->create($data, $this->input->post('groups'));
if($create == true) {
$this->session->set_flashdata('success', 'Successfully created');
redirect('users/', 'refresh');
}
else {
$this->session->set_flashdata('errors', 'Error occurred!!');
redirect('users/create', 'refresh');
}
}
else {
// false case
$group_data = $this->model_groups->getGroupData();
$this->data['group_data'] = $group_data;
$this->render_template('users/create', $this->data);
}
}
Ví dụ minh họa 2
public function __construct()
{
parent::__construct();
//Check if user is logged in or id exists in session
if ($this->session->userdata('user_id')) {
} else {
redirect(base_url() . 'index.php/Users/login');
}
}
Hy vọng bài viết này hữu ích cho các bạn. Cảm ơn các bạn đã theo dõi


