{{ base_url }} for Pagination - Antimatter Theme

I’m having trouble getting navigation links to work. I think it’s related to base_url and I’m wondering if you can point me to a place where I can change base_url so that it captures server name?

== Background ==
In order to make tags for taxonomylist, archive and blog items to work on my Grav 0.9.6 with Nginx, I modified base_url similar to “{{ base_url_relative}} is empty” post.

== Details ==

  • In “user/themes/antimatter/templates/partials/blog_item.html.twig” I changed <a href="{{ base_url }}/tag:{{ tag }}">{{ tag }}</a> to <a href="{{ base_url == '' ? '/' : base_url_relative }}/tag:{{ tag }}">{{ tag }}</a>.

NOTE: I had to do that in Antimatter v1.1.8 – In Antimatter v1.1.11, I don’t have to modify blog_item.html.twig.

  • In “user/plugins/taxonomylist/templates/taxonomylist.html.twig” changed to <a href="{{ base_url == '' ? '/' : base_url_relative }}/tag:{{ tax|e('url') }}">{{ tax }}</a>

  • In “user/plugins/archives/templates/partials/archives.html.twig” changed to <a href="{{ base_url == '' ? '/' : base_url_relative }}/month:{{ month|date('M _Y')|lower|e('url') }}">

The only outstanding item left in my setup is page navigation at the bottom of the (home) page. For example, for my Grav server name I use “sub.localhost” – For page 2, instead of “sub.localhost:port/page:2” the link at the bottom of the page is just “page:2”.

I placed a test.php in my Grav root directory containing: <pre><?php var_export($_SERVER)?></pre>. Output when with a web browser I request “sub.localhost/test.php/foo/bar.php?v=1”:

array (
  'USER' => 'www',
  'HOME' => '/var/www',
  'FCGI_ROLE' => 'RESPONDER',
  'SCRIPT_FILENAME' => '/grav/test.php',
  'PATH_INFO' => '/foo/bar.php',
  'PATH_TRANSLATED' => '/grav/foo/bar.php',
  'QUERY_STRING' => 'v=1',
  'REQUEST_METHOD' => 'GET',
  'CONTENT_TYPE' => '',
  'CONTENT_LENGTH' => '',
  'SCRIPT_NAME' => '/test.php',
  'REQUEST_URI' => '/test.php/foo/bar.php?v=1',
  'DOCUMENT_URI' => '/test.php/foo/bar.php',
  'DOCUMENT_ROOT' => '/grav',
  'SERVER_PROTOCOL' => 'HTTP/1.1',
  'GATEWAY_INTERFACE' => 'CGI/1.1',
  'SERVER_SOFTWARE' => 'nginx/1.6.0',
  'REMOTE_ADDR' => '10.0.2.2',
  'REMOTE_PORT' => '63736',
  'SERVER_ADDR' => '10.0.2.15',
  'SERVER_PORT' => '80',
  'SERVER_NAME' => 'sub.localhost',
  'REDIRECT_STATUS' => '200',
  'HTTP_HOST' => 'sub.localhost:7890',
  'HTTP_CONNECTION' => 'keep-alive',
  'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*; q=0.8',
  'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Iron/37.0.2000.0 Chrome/37.0.2000.0 Safari/537.36',
  'HTTP_DNT' => '1',
  'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
  'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
  'PHP_SELF' => '/test.php/foo/bar.php',
  'REQUEST_TIME_FLOAT' => 1416732931.3755169,
  'REQUEST_TIME' => 1416732931,
)

Can you try just setting absolute_urls to true in your system configuration?

This will make all base_url references use the full http://server:port/ur type syntax.

If you just wish some URLs to be full, you can still use base_url_absolute variable in the Twig rather than base_url

More info in the Twig Variables Docs

Thanks – I tried it and the link was still only “page:2”. Should I maybe look in overriding it in the “/user/plugins/pagination/templates/pagination.html.twig” template file, similar to what I did for “taxonomylist”, “archive” and “blog item”? I tried using the same replacement as for those three in the “pagination.html.twig” but that didn’t work.

I also noticed that while I need to change .twig template files for those three, the “Syndicate” tagging works out of the box and I don’t need to change its “user/plugins/feed/templates/feed.atom.twig” config.

I really am still not sure why the latest version of Antimatter is not working out of the box for you. I did some extensive testing in a variety of setups to ensure that the last round of fixes should work with all possible variations, and it should be setting the base_url correctly in the blog page, and in the item page. All the other bits (taxonomy/pagination/feeds/random/etc) should be using this same base_url and should not need to be edited in any way.

I guess when I get home later today I’ll have another look in case i missed some scenario.

Thanks so much for the quick reply! I will also continue looking into it.

I had forgotten to re-release the pagination plugin with a fix that was needed. If you update that with GPM it should sort it.

Yes, that fixed it!!

Many, many thanks!!