Can anybody help me understand the way the partials view helper was
designed and how it works? My tests are showing results that are not
intuitive. Perhaps my setup is incorrect, or my usage is. If anyone
could help or help me understand the workings, that would be GREAT!
Setup:
Simple test setup using module structure
modules/
default/
controllers/
VtestController.php
views/
scripts/
vtest/
index.phtml
test1.phtml
partials/
test2.phtml
VtestController.php:
public function indexAction() {}
index.phtml:
Hello
test1.phtml:
Test 1
partials/test2.phtml
Test 2
Starting Setup : works (Hello)
* VtestController - $this->render('test1') : *works *(Test 1)
* VtestController - $this->render('test1.phtml') : *fails *script
'vtest/test1-phtml.phtml' not found in path
(/directory/modules/default/views/scripts/)
* VtestController - $this->render('partials/test2') : *works *(Test 2)
* VtestController - $this->render('partials/test2.phtml') : *fails
*script 'vtest/partials/test2-phtml.phtml' not found in path
(/directory/modules/default/views/scripts/)
Ok... So far so good. From inside the action controller, rendering
works without passing the extension and subdirectories are ok. Right?
Now, back to a blank VtestController and playing around with the
partials view helper.
* index.phtml = 'Hello <?=$this->partial('test1')?>' : *fails
*script 'test1' not found in path
(/directory/modules/default/views/scripts/)
* index.phtml = 'Hello <?=$this->partial('test1.phtml')?>' : *fails
*script 'test1.phtml' not found in path
(/directory/modules/default/views/scripts/)
* index.phtml = 'Hello <?=$this->partial('vtest/test1.phtml')?>' :
*works *(Hello. Test 1)
* index.phtml = 'Hello <?=$this->partial('vtest/test1')?>' : *fails
*script 'vtest/test1' not found in path
(/directory/modules/default/views/scripts/)
* index.phtml = 'Hello <?=$this->partial('partials/test2')?>' :
*fails *script 'partials/test2' not found in path
(/directory/modules/default/views/scripts/)
* index.phtml = 'Hello <?=$this->partial('partials/test2.phtml')?>'
: *fails *script 'partials/test2.phtml' not found in path
(/directory/modules/default/views/scripts/)
* index.phtml = 'Hello
<?=$this->partial('vtest/partials/test2.phtml')?>' : *works
*(Hello. Test 2)
* index.phtml = 'Hello <?=$this->partial('vtest/partials/test2')?>'
: *fails *script 'vtest/partials/test2' not found in path
(/directory/modules/default/views/scripts/)
Ok. So, if partials are used, you have to include the controller name
and include the extension. Right?
Now, I'll try to get partial test1 to include partial test2.
* index.phtml = 'Hello <?=$this->partial('vtest/test1.phtml')?>' -
test1.phtml = 'Test 1
<?=$this->partial('vtest/partials/test2.phtml')?>' : *works
*(Hello. Test 1 Test 2)
And I'm sure you can imagine all of the other iterations that will fail.
I know I can extend the include path and/or use __FILE__ for a relative
starting position for the partial, but wouldn't it make sense for that
to be the default? Also, shouldn't the extension be automatically
appended, like when using render inside of an action controller?
Any help is appreciated.
Arthur