4.B. Reference Handlebars Helpers - CradlePHP/Cradle GitHub Wiki
- 4.B.1. capital
- 4.B.2. upper
- 4.B.3. lower
- 4.B.4. chars
- 4.B.5. words
- 4.B.6. strip
- 4.B.7. markdown
- 4.B.8. number
- 4.B.9. price
- 4.B.10. formula
- 4.B.11. number_format_short
- 4.B.12. date
- 4.B.13. relative
- 4.B.14. join
- 4.B.15. split
- 4.B.16. scope
- 4.B.17. query
- 4.B.18. sorturl
- 4.B.19. sortcaret
- 4.B.20. redirecturl
- 4.B.21. pager
- 4.B.22. or
- 4.B.23. when
- 4.B.24. otherwise
- 4.B.25. has
- 4.B.26. hasnt
- 4.B.27. in
- 4.B.28. notin
- 4.B.29. compile
- 4.B.30. partial
- 4.B.31. inspect
- 4.B.32. fileinfo
- 4.B.33. request
- 4.B.34. response
- 4.B.35. _
- 4.B.36. settings
Cradle uses Handlebars for the templating engine. We chose Handlebars for it's simplicity and it's availability in other programming languages. As well as the original Handlebars helpers. Cradle adds over 30 more reusable helpers to use within your templates.
Capitalizes the given value.
- string The string to parse
<!-- Foo Bar -->
{{capital 'foo bar'}}
<!-- Bar -->
{{capital foo}}
Uppercases the given value.
- string The string to parse
<!-- FOO BAR -->
{{upper 'foo bar'}}
<!-- BAR -->
{{upper foo}}
Lowercases the given value.
- string The string to parse
<!-- foo bar -->
{{lower 'Foo Bar'}}
<!-- bar -->
{{lower foo}}
Limits the output by the given amount of characters.
- string The string to parse
- int The amount of characters to show
<!-- foo -->
{{chars 'foo bar' 3}}
<!-- b -->
{{chars foo 1}}
Limits the output by the given amount of words.
- string The string to parse
- int The amount of words to show
<!-- foo -->
{{words 'foo bar' 1}}
<!-- Went to -->
{{words zoo 2}}
Strip HTML tags
- string The string to parse
<!-- foo bar -->
{{strip '<b>foo</b> <em>bar</em>'}}
<!-- foo <em>bar</em> -->
{{strip '<b>foo</b> <em>bar</em>' '<em>'}}
Converts markdown to HMTL
- string The string to parse
<!-- foo <em>bar</em> -->
{{markdown 'foo *bar*'}}
Formats a number using commas and decimals
- int The number to parse
- int The number of decimal places
<!-- 1,000 -->
{{number 1000}}
<!-- 1,000.00 -->
{{number 1000 2}}
Formats a number to a price format
- int The number to parse
<!-- 1,000.00 -->
{{price 1000}}
Computes the given formula
- string The template string to parse
{{formula '1000 + {{amount}}'}}
Returns a short version of the number
- int The number to parse
<!-- 100 -->
{{number_format_short 100}}
<!-- 1K -->
{{number_format_short 1000}}
<!-- 1M -->
{{number_format_short 1000000}}
Returns a date time format
- string The raw date
- string The date format
<!-- January 01, 2018 -->
{{date '2018-01-01' 'F d, Y'}}
Returns a date time format relative to now
- string The raw date
- string The date format
<!-- 3 months ago -->
{{relative '2018-01-01' 'F d, Y'}}
Transforms an array to string
- array The array to join
- string The separator
<!-- 1, 2 -->
{{join '1 2' ', '}}
Splits a string into an array
- string The string to split
- string The separator
<!-- foo,bar,zoo, -->
{{#split 'foo,bar,zoo' ','}}{{this}},{{/split}}
Traverses into the specified array path
{{#scope list '0'}}
{{@key}} -> {{this}}
{{/scope}}
Manipulates $_GET and returns the final query
- if 1 argument, will return the key value in $_GET (should be scalar)
- if 2 or more arguments, will set the path and return the final query
{{query 'q'}}
{{query 'q' 'foobar'}}
Manipulates sort order and returns the final query
- string[,string..] url path
<!-- look for the sorting value at ?order[profile_id] -->
{{sorturl 'order' 'profile_id'}} //--> ASC|DESC|null
Determines the caret to be used (needs fontawesome 5)
- string[,string..] url path
<!-- look for the sorting value at ?order[profile_id] -->
{{sortcaret 'order' 'profile_id'}} //--> <i class="fas fa-caret-up"></i>|<i class="fas fa-caret-down"></i>|null
Returns the current url encoded, used for recdirect flags
{{redirecturl}}
Uses a block to generate the pagination
- int total
- int range
<ul>
{{#pager 200 50}}
<li>{{page}}</li>
{{/pager}}
</ul>
- If the 1st argument is populated and evaluates to true, the same argument will be returned
- Otherwise the 2nd argument will be returned
- scalar The value to be tested
- scalar The default value otherwise
{{or 1 0}}
A better if statement for handlebars.
- scalar The comparative value 1
- string The comparative operator
- scalar The comparative value 2
==
===
!=
!==
<
<=
>
>=
||
&&
<!-- No -->
{{#when 1 '===' '1'}}
Yes
{{else}}
No
{{/if}}
The opposite of when
- scalar The comparative value 1
- string The comparative operator
- scalar The comparative value 2
==
===
!=
!==
<
<=
>
>=
||
&&
<!-- Yes -->
{{#otherwise 1 '===' '1'}}
Yes
{{else}}
No
{{/if}}
Checks to see if a key exists
- array The array
- string The key
{{#has post 'title'}}
Yes
{{else}}
No
{{/if}}
Checks to see if a key does not exists
- array The array
- string The key
{{#hasnt post 'title'}}
Yes
{{else}}
No
{{/if}}
Checks to see if the given array has a value
- array The array
- scalar The value
{{#in post 'title'}}
Yes
{{else}}
No
{{/if}}
Checks to see if the given array does not have a value
- array The array
- scalar The value
{{#notin post 'title'}}
Yes
{{else}}
No
{{/if}}
Calls the compiler again to compile the given string (recursive)
- string The template
- array The template variables
{{compile '{{post_title}}' post}}
Calls the compiler again to compile the given string (recursive)
- string The name of the partial
- array The template variables
{{partial 'name' post}}
Calls the compiler again to compile the given string (recursive)
- mixed Force outputs any handlebars variables
{{inspect post}}
Reads the given filename and determines the file information
- string Path of the file
{{#fileinfo '/some/path/to/image.jpg'}}
{{name}} - image.jpg
{{base}} - image
{{path}} - /some/path/to
{{extension}} - jpg
{{mime}} - image/jpg
{{/fileinfo}}
Gives access to the current request object
- scalar[,scalar..] The request path
<!-- 127.0.0.1 -->
{{request 'server' 'HTTP_HOST'}}
Gives access to the current response object
- scalar[,scalar..] The response path
<!-- false -->
{{response 'json' 'error'}}
i18n translation engine. Translate the given string based on the current language.
- string The string to be translated
<!-- nom -->
{{_ 'Name'}}
Returns the settings in config/settings.php
- string The key in settings
<!-- dev -->
{{settings 'environment'}}