This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons.
The Craft CMS 3.x version of this plugin can be found here: craft-pathtools and can also be installed via the Craft Plugin Store in the Craft CP.
This twig plugin for the Craft CMS brings convenient path & url manipulation functions & filters to your Twig templates.
Related: PathTools for Craft 3.x
To install PathTools, follow these steps:
- Download & unzip the file and place the
pathtools
directory into yourcraft/plugins
directory - -OR- do a
git clone https://github.com/khalwat/pathtools.git
directly into yourcraft/plugins
folder. You can then update it withgit pull
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
pathtools
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
All of the functionality offered by PathTools can be used either as a filter, e.g.:
{{ myAsset.url | basename }}
Or as a function, e.g.:
{% set myBaseName = basename(myAsset.url) %}
Wrapper for the php pathinfo() function -- http://php.net/manual/en/function.pathinfo.php
Wrapper for the php basename() function -- http://php.net/manual/en/function.basename.php
Wrapper for the php dirname() function -- http://php.net/manual/en/function.dirname.php
Wrapper for the php parse_url() function -- http://php.net/manual/en/function.parse-url.php
Wrapper for the php parse_str() function -- http://php.net/manual/en/function.parse-str.php
Can be passed either a path or a url, and it will return the path or url with the filename extension changed, e.g.:
<source src="{{ myAsset.url | swap_extension('mp4') }}" type='video/mp4' />
<source src="{{ myAsset.url | swap_extension('webm') }}" type='video/webm' />
For myAsset.url
= http://www.coolvids.com/content/vids/MyCoolVid.mp4
the output would be:
<source src="http://www.coolvids.com/content/vids/MyCoolVid.mp4" type='video/mp4' />
<source src="http://www.coolvids.com/content/vids/MyCoolVid.webm" type='video/webm' />
Can be passed either a path or a url, and it will return the path or url with the directory path changed, e.g.:
<img src="{{ myAsset.url | swap_directory('/over/there') }}" />
For myAsset.url
= http://www.coolvids.com/not/here/rock.pdf
the output would be:
<img src="http://www.coolvids.com/over/there/rock.pdf" />
Can be passed either a path or a url, and it will return the path or url with the suffix appended to the filename, e.g.:
<img src="{{ myAsset.url | append_suffix('@2x') }}" />
For myAsset.url
= http://www.coolvids.com/img/ux/search.png
the output would be:
<img src="http://www.coolvids.com/img/ux/[email protected]" />
- [Added] Added the parse_str() function
- [Improved] Updated the README.md
- [Added] Added support for Craft 2.5 new plugin features
- [Improved] Updated the README.md
- Initial release