Get a Demo
Table of contents

path_info Link

The path_info function parses a file path and returns its components. 

The values returned can include:

  • basename - the filename including the extension
  • dirname - the path up to the filename
  • extension - the file extension - this is the only value that may be missing if the file path doesn't contain a file extension
  • filename - the file name minus the extension

If only a specific file path part is required then that can be passed as the second parameter. If it exists in the file path then it will be returned. Otherwise false will be returned.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.

Example Link

{% set path = '/path/to/file/myfile.pdf' %}
{% set fileParts = path_info('/path/to/myfile.pdf) %}
{# The above example will return #}
array (
    'basename' => 'myfile.pdf',
    'dirname' => '/path/to',
    'extension' => 'pdf'
    'filename' => 'myfile'
)

Arguments Link

The path_info function has the following signature.

path_info(path, part)
Arguments Description
path The file path value to parse.
part

The single file path part to return. If the part exists in the file path then it will be returned. Otherwise false is returned. Typically that would only happen with "extension".

If the part exists in the URL then the value returned is a string.

Valid part values are:

  • basename
  • dirname
  • extension
  • filename
Get Started With Aptuitiv