Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to properly override / add views in applications/dashboard/views/home?

MasterOneMasterOne ✭✭
edited May 2013 in Vanilla 2.0 - 2.8

I want to override privacypolicy.php (to be based on the code of termsofservice.php, which makes it possible to write up your own policy in the locale definitions) and add a similar page called legalnotice.php.

What I did:

  • Copy applications/dashboard/views/home/termsofservice.php to themes/customtheme/views/home and rename it to privacypolicy.php

  • Copy privacypolicy.php as legalnotice.php in that folder

  • Edit the text definitions in those files accordingly

  • Call those pages from the footer like

    < a id="TermsOfService" class="Popup" target="terms" href="/home/termsofservice">Terms of Service< /a >

    < a id="PrivacyPolicy" class="Popup" target="privacy" href="/home/privacypolicy">Privacy Policy< /a >

    < a id="LegalNotice" class="Popup" target="legal" href="/home/legalnotice">Legal Notice< /a >

But it doesn't work that way:

  • Terms of Service is showing up correctly (as it comes unaltered from the original folder)

  • Privacy Policy is only showing the h1 heading but not the actual text and it's unformated on a white page when viewed with javascript disabled (compared to the nice page you get when viewing /home/termsofservice)

  • Legal Notice is not showing at all (leading to the "Page Not Found" error page)

There has to be at trick to it which I don't know yet. I want all three pages to be similar formated (to look as /home/termsofservice) and have the content coming from the locale definitions file.

Any ideas?

Tagged:

Comments

  • To override views, you must copy them in the same path in your theme, like you did, and keep the same file name. That is, just copy dashboard/home/views/termsofservice.php to yourtheme/home/views and it will be picked up from your theme folder.

    Add other pages, you must implement some theme hooks that take care of loading the appropriate files.

  • MasterOneMasterOne ✭✭
    edited May 2013

    @businessdad

    The copied file privacypolicy.php is in the right place (themes/customtheme/views/home/), as is the new one (legalnotice.php), so I guess it has something to do with the functions from class.homecontroller.php.

    I played around trying to make something happen in the custom theme hooks file for enabling the use of legalnotice.php but so far no effect, which means I have no idea what I am doing.

    Any clue on how to replicate the functionality from class.homecontroller.php for legalnotice.php (the new page) and privacypolicy.php (which has the inclusion of markdown.php missing in class.homecontroller.php) in class.customthemehooks.php?

  • You need to create the methods on the home controller to display your new views.

    public function HomeController_LegalNotice_Create($Sender) {
      $Sender->Render();
    }
    

    I am not sure what version of Vanilla you are using, but in 2.0.18.8, PrivacyPolicy and TermsOfService are already defined on the homecontroller.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @hgtonight

    I'm on 2.1b1. The PrivacyPolicy definition on the homecontroller is lacking the following line (as they hardcoded the text into privacypolicy.php):

    require_once PATH_LIBRARY.'/vendors/markdown/markdown.php';

    So I need to add the function for LegalNotice and override PrivacyPolicy to include that line.

    Do I now have to make the modifications in class.homecontroller.php, or can I do it in class._custom_themehooks.php (and does the naming of the function matter?)?

  • Since this is a controller (which is pluggable), we can use magic events instead of modifying core files. You should be able to do the following.

    public function HomeController_PrivacyPolicy_Override($Sender) {
      // This method gets called in place of the HomeController's PrivacyPolicy method.
      require_once PATH_LIBRARY.'/vendors/markdown/markdown.php';
      $Sender->Render();
    }
    
    public function HomeController_LegalNotice_Create($Sender) {
      require_once PATH_LIBRARY.'/vendors/markdown/markdown.php';
      $Sender->Render();
    }
    

    Haven't tested it (no 2.1b1 install atm), so let me know if it works or not. :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • MasterOneMasterOne ✭✭
    edited May 2013

    @hgtonight

    That magic is indeed working!

    There is only one awkward problem:

    HomeController_PrivacyPolicy_Override doesn't work for some reason (as if markdown.php is not included, the resulting page is not rendered correctly, but only contains the unformated h1 title on a white page), however HomeController_PrivacyPolicy_Create does the job!

  • I just re-read the documentation on Magic Events. Looks like _Override only works on the Render() method. Sorry about that.

    Glad to hear you got it working!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.