--- layout: default permalink: extensions/uri/ title: URI extension --- URI === The URI extension is designed to make URI checks within templates easier. The most common use is marking the current page in a menu as "selected". It only has one function, `uri()`, but can do a number of helpful tasks depending on the parameters passed to it. ## Installing the URI extension The URI extension comes packaged with Plates but is not enabled by default, as it requires an extra parameter passed to it at instantiation. ~~~ php // Load URI extension using global variable $engine->loadExtension(new League\Plates\Extension\URI($_SERVER['PATH_INFO'])); // Load URI extension using a HttpFoundation's request object $engine->loadExtension(new League\Plates\Extension\URI($request->getPathInfo())); ~~~ ## URI example ~~~ php ~~~ ## Using the URI extension Get the whole URI. ~~~ php uri()?> ~~~ Get a specified segment of the URI. ~~~ php uri(1)?> ~~~ Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns `true` on success or `false` on failure. ~~~ php uri(1, 'home')): ?> ~~~ Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns string (third parameter) on success or `false` on failure. ~~~ php uri(1, 'home', 'success')?> ~~~ Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns string (third parameter) on success or string (fourth parameter) on failure. ~~~ php uri(1, 'home', 'success', 'fail')?> ~~~ Check if a regular expression string matches the current URI. Returns `true` on success or `false` on failure. ~~~ php uri('/home')): ?> ~~~ Check if a regular expression string (first parameter) matches the current URI. Returns string (second parameter) on success or `false` on failure. ~~~ php uri('/home', 'success')?> ~~~ Check if a regular expression string (first parameter) matches the current URI. Returns string (second parameter) on success or string (third parameter) on failure. ~~~ php uri('/home', 'success', 'fail')?> ~~~