Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samuell/pwutils
Utility functions for writing templates for the ProcessWire CMS
https://github.com/samuell/pwutils
Last synced: about 2 months ago
JSON representation
Utility functions for writing templates for the ProcessWire CMS
- Host: GitHub
- URL: https://github.com/samuell/pwutils
- Owner: samuell
- Created: 2014-04-23T09:20:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-09T22:13:47.000Z (over 10 years ago)
- Last Synced: 2024-10-08T20:05:03.978Z (3 months ago)
- Language: PHP
- Size: 289 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PW Utils
========Utility functions for writing templates for the [ProcessWire CMS](http://processwire.com/)
Might even be viewed as a kind of optional "template language" for ProcessWire.
Basic idea
----------
The basic idea of this micro-library is to make writing things like this simpler:
````php
echo "
- ";
- Home ";
- " . $child->title . " ";
echo "
foreach( $page->children as $child ) {
echo "
}
echo "
````
With PW Utils, one would instead write:
````php
echo ul( li( 'Home' ) .
do_for( $page->children, function($p) {
return li( a( $p->title, $p->url ) );
})
);
````
This might not look as very big changes at first, but our experience is that when working
practically with the templating, the more "functional" (rather than string-padding:y)
approach in PWUtils, makes it much easier to make changes to the code without breaking
the number of quotes, and also tends to make the code a slight bit easier to read, in
our opinion.
Installation
------------
1. cd /site/templates
2. git clone https://github.com/samuell/pwutils.git
3. ln -s pwtutils/pwutils.php .
4. Add the following code at the top, inside your template php files:
````php
````
More Examples
-------------
Find a few more examples below:
### Linking Sibling pages
#### Without PWUtils
````php
echo '
````
#### With PWUtils
````php
$a_attrs = array( 'class' => 'nav-link' );
$div_attrs = array( 'class' => 'w-col w-col-8 navigation-column' );
echo div( a( '/', 'Welcome', $a_attrs ) .
do_for( $page->siblings, function($p) {
return a( $p->url, $p->title, $a_attrs );
} ),
$div_attrs
);
````
### Linking and styling images
#### Without PWUtils
````php
foreach( $page->image as $img ) {
echo "";
echo "";
echo "";
}
````
#### With PWUtils
````php
$styleattrs = array( 'style' => 'border: 1px solid black;' );
foreach( $page->image as $img ) {
echo a( $img->url, img( $img->url, 'Some alt-text', $styleattrs ));
}
````