Skip to content

Commit 902489a

Browse files
author
Andrew
committed
add convention for double underscores instead of slashes in element path (for JS variable compatibility)
1 parent 1959336 commit 902489a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mustache.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
*
1515
* A few conventions:
1616
*
17-
* Element: the name of the element - like you would use in CakePHP.
18-
* For example users/name corresponds to app/views/elements/users/name.mustache
17+
* Replace / in an element path with __ - taht way Javascript can deal with it.
18+
*
19+
* Element: the name of the element - like you would use in CakePHP, but replace '/' with '__'
20+
* For example users__name corresponds to app/views/elements/users/name.mustache
1921
*
2022
* Template: the text string from an element, which is read from the element file.
2123
* This is what gets passed into Mustache for conversion to HTML
@@ -24,6 +26,8 @@
2426
* your element, simply use the element convention in the proper context!
2527
* Mustache takes care of the Data context
2628
*
29+
*
30+
*
2731
*/
2832

2933
require_once ROOT . '/app/vendors/mustache/Mustache.php';
@@ -70,6 +74,7 @@ function element( $element, $values = array() ) {
7074
* @return string - system path to the element for PHP fread functions
7175
*/
7276
private function _getElementPath( $element ) {
77+
$element = str_replace('__', '/', $element);
7378
return ROOT . DS . 'app' . DS . 'views' . DS . 'elements' . DS . $element . '.' . $this->ext;
7479
}
7580

0 commit comments

Comments
 (0)