简体   繁体   中英

Drupal/Twig/Symfony Routing Returns “null” for base_url

I have been researching for almost 2 weeks on for an answer and have finally decided I needed to ask for help. I am quite unfamiliar with PHP/Drupal but has inherited such a project to update and maintain. The project runs on Drupal 8.3.7 and is hosted with IIS 6.2.

For some unknown reason, links in my html.twig files are being returned with a "null" base_url. So for example...

<a href="/home"> ... </a>

will link to "null/home" ... After a lot of hacking and trying to figure out if I could manually set $base_url (not a best practice, I know, but I just needed to see if it was possible), I found two peculiar behaviors:

A. If in the associated controller I create a variable $temp_base_url and hardcode the value "localhost" and attempt to put the following in my html.twig file (where item.url = "/home")...

<a href="http://{{temp_base_url}}{{item.url}}">http://{{temp_base_url}}{{item.url}}</a>

The text between the anchor tag will show up correctly as http://localhost/home while the actual link will direct you to null/home .

B. On the other hand, if I assigned $temp_base_url to equal " http://localhost " and put the following code...

<a href="{{temp_base_url}}{{item.url}}">{{temp_base_url}}{{item.url}}</a>

The text between the anchor tag will (aga) show up correctly as http://localhost/home while the actual link will now try to direct you to http://localhost/null/home .

The problem isn't with the global variable $base_url because when I test for this within the Controller, $base_url is setting itself correctly to "localhost" so I suspect Symfony or something else rendering the routes incorrectly (any attempts to use 'path' or 'url' has also resulted in similar null issues).

So my question is: Where are these nulls coming from? How do I get IIS/Drupal to pick up the appropriate base url for routing?

您可以使用此url('<front>')

{{ url('<front>') }}{{item.url}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM