phpcakephpcakephp-1.3

CakePHP themed plugin view


Is it possible to theme a plugin's view? I have a mobile theme for mobile devices and would like to use different view files for a plugins app/views as well. I have tried app/views/themed/THEME/plugin/... and /app/plugins/PLUGIN/views/themed/THEME/...none seem to work. Thanks in advance.


Solution

  • Cakephp 2.x supports this without having to make any code changes:

    If you (can) convert to using cakephp 2.x then yes you can (automatically). The view paths for a theme 'mytheme' and a plugin 'Permissions' would be:

    Array
    (
        [0] => /var/vhosts/Project/htdocs/app/View/Themed/Mytheme/Plugin/Permissions/
        [1] => /var/vhosts/Project/htdocs/app/View/Themed/Mytheme/
        [2] => /var/vhosts/Project/htdocs/app/View/Plugin/Permissions/
        [3] => /var/vhosts/Project/htdocs/app/Plugin/Permissions/View/
        [4] => /var/vhosts/Project/htdocs/app/View/
        [5] => /var/vhosts/Project/htdocs/lib/Cake/View/
        [6] => /var/vhosts/Project/htdocs/lib/Cake/Console/Templates/skel/View/
    )
    

    So if you had Users/index.ctp in the plugin and wanted to override it you would edit:

    /var/vhosts/Project/htdocs/app/View/Themed/Mytheme/Plugin/Permissions/Users/index.ctp
    

    for the themed version OR:

    /var/vhosts/Project/htdocs/app/View/Plugin/Permissions/Users/index.ctp
    

    for the non themed version