sitegeist/base-url

Determinates base URL from site configurations for scripts where no FE or BE context is available like commands or tasks

Installs: 22 954

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 5

Forks: 1

Open Issues: 1

Type:typo3-cms-extension

v1.1.7 2024-04-03 06:58 UTC

README

In in scripts where no FE or BE context is available and you want to build URLs its a good idea to get the absolute URL from a site configuration. This extension provides a helper class to get there.

Where to use

  • commands which are called via cli
  • scheduler tasks

Features

  • get base URL depending on site configurations
  • absolute a relative URL

Getting Started

use the static functions from BaseUrl helper Class

\Sitegeist\BaseUrl\Helper\BaseUrl::get(); // https://example.com/
\Sitegeist\BaseUrl\Helper\BaseUrl::prepend('home.html'); // https://example.com/home.html

use the viewhelpers in your fluid templates e. g. for mails

<baseurl:get /> <!-- https://example.com/ -->
<baseurl:prepend>home.html</baseurl:prepend> <!-- https://example.com/home.html -->

Multiple site configuration setups

if your system has more than one site configuration, you can specify which site configuration should be used by:

  • specify site configuration identifier

    BaseUrl::get('mysite');
    BaseUrl::prepend('home.html', 'mysite');
    <baseurl:get identifier="mysite" />
    <baseurl:prepend identifier="mysite" />home.html</baseurl:prepend>
  • specify a pageUid (anywhere in the pageTree)

    BaseUrl::get(null, 1);
    BaseUrl::prepend('home.html', null, 1);
    <baseurl:get pageId="1" />
    <baseurl:prepend pageId="1" />home.html</baseurl:prepend>

Getting further

Disable $asString return type to get an TYPO3\CMS\Core\Http\Uri object. Now you can get or change specific parts of the url.

BaseUrl::get(null, null, true, false);

BaseUrl::prepend('home.html', null, null, true, false);
/*
TYPO3\CMS\Core\Http\Uri prototype object
   scheme => protected "https" (5 chars)
   supportedSchemes => protected array(2 items)
      http => 80 (integer)
      https => 443 (integer)
   authority => protected "" (0 chars)
   userInfo => protected "" (0 chars)
   host => protected "example.com" (11 chars)
   port => protected NULL
   path => protected "home.html" (9 chars)
   query => protected "" (0 chars)
   fragment => protected NULL
*/