in a codeigniter controller load->view how can I add a Anchor Tags To Jump To the Specific Location

In a codeigniter controller how can I add a Anchor Tags To Jump To the Specific location in a page view. Example in a normal link : Link to access in the section

In the codeigniter controller I'm using : $data['title'] = 'Page view title'; $this->load->view('controller/page_view#destination', $data); but not working.

It works with redirect(controller/page_view#destination) but dont pass on $data.

I need your help.

Thierry

Upvotes: 1

Views: 395

Answers (1)

Tpojka
Tpojka

Reputation: 7111

Pass one more variable in $data array.

$data['pageSection'] = 'destination';
$this->load->view('controller/page_view', $data);

Then in view file make JS code block that will scroll to that section:

$(document).ready(function(){
    $("html, body").animate({ scrollTop: $('#<?php echo $pageSection;?>').offset().top }, 1000);
});

It need to be in same view file, not in separate JS file for variable to be available.

Upvotes: 3

Related Questions