문제

I am using blade templating and I want to make the users navigate to a point on a page when they click on a link. This is my view :-

View::make($data->path)->with('data', $data)->with('title', $title);

My path is being fetched from the database.

There is a link:-

 <a id="middle">Welcome to the user section</a>

Now I don't think putting #middle in make() will help :-

I tried this:-

 View::make($data->path."php#middle")->with('data', $data)->with('title', $title);

and

View::make($data->path.".blade.php#middle")->with('data', $data)->with('title', $title);

but neither seems to work.

How can i make this work?

도움이 되었습니까?

해결책

Your view is just the file to render -- you shouldn't confuse it with the request URL, which is determined by routes.

All you need to do is add the anchor to the URL the user clicks to get to this location, on the end of your route. If it's not something you can determine at the time the link is generated, you should use a redirect in your logic to the URL you wish to include.

That said, you could also pass a variable to your page that javascript uses to scroll the page to the appropriate location as well:

View::make($data->path)->with('data', $data)->with('title', $title)->with('scroll', 'middle');

Then, on your page, in javascript:

document.getElementById('{{ $middle }}').scrollIntoView();

다른 팁

override getRedirectUrl :

protected function getRedirectUrl()
{
    $url = $this->redirector->getUrlGenerator();
    return $url->previous() . '#hashid';
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top