We help IT Professionals succeed at work.

How do I incorporate a # dynamic in a Laravel route?

Bruce Gust
Bruce Gust asked
on
High Priority
51 Views
Last Modified: 2020-03-07
I've got a page with a list of testimonials and at one point on the site, I have this:

<a href="testimonials#{{$test->id}}">read more...</a>

The idea being that when the user clicks on the link, they're taken to the http://nomas.site/testimonials#2 and advanced to the testimonial with the id of 2.

I've got that particular testimonial listed with a <a name="2"></a> like you would expect but it doesn't seem to work.

Any ideas?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
Hey Bruce,

There's nothing fundamentally wrong with your code. I'm assuming you're using HTML5, because in 4, you could have names that began with a number. Other than that, everything looks good.

As a sanity check, view the source of both pages to make sure the HTML being output does actually contain the HTML you think it does.

What do you mean by not working - do you have a link to the page we can take a look at.
Bruce GustPHP Developer

Author

Commented:
Everything is on my local box right now, but the link looks like this:

http://nomas.site/testimonials#2

Now, something's happening because the page does advance to a position other than the top of the content, but it's the same position every time which is what lead me to believe that something was "off."

If you're telling me that everything looks good from you standpoint, I'll go back and pop the hood on this and see if I'm not missing something obvious. My biggest concern was that there might be something within the Laravel paradigm that required a special accommodation for a route followed by a "#" character.
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
OK Bruce,

No ... nothing special in Laravel and your code looks good.

Like I said, view the source of the page that contains the links to make sure they're all working properly, and then view the source of your testimonials page so make sure the <a> tags have their name set correctly.

FYI - you don't have to use an empty <a> tag for this - it'll work just as well with an ID on an element, such as a DIV.

<div id="1">
    ...
</div>

<div id="2">
    ...
</div>

Open in new window

Bruce GustPHP Developer

Author

Commented:
I figured it out, Chris!

The # dynamic was working. The problem was that the content of the page would go all the way to the top of the page behind the header portion so you couldn't see / tell what was going on.

Bottom line: I got it done!

Thanks!