1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

How I created my external pages.

Discussion in 'Development Tutorials [Archive]' started by robdog, Mar 29, 2011.

  1. robdog

    robdog Well-Known Member

    I decided to to a post here instead of making a plugin. If someone wants to take this and make a plugin, go for it. You guys are free to do whatever you want to the code. :)

    Setup/Installation is pretty easy. Follow the steps and you should be good to go.
    1. Extract the attached file into your library folder.
    2. Create an Add-on (you will need to have the debug flag set in your config)
      Add-on ID: External Pages
      Title: External Pages
      Version String: 1
      Version ID: 1
    3. Create a route at the following URL:
      Route Prefix: en
      Route Type: Public
      Route Class: ExternalPages_Route_Prefix_En
      Use Class to Build Link: Always
      Add-On: External Pages
    4. Create a Code Event Listener (optional if you want to add nav tabs for your external pages)
      Listen to Event: navigation_tabs
      Execute Callback: ExternalPages_Listeners_Navigation::navtabs
      Callback Execution Order: 1
      Add-on: External Pages
    You are pretty much done, but you are DEFINITELY going to want to customize further and you still need to add the templates. (so continue reading :p)

    Now you might not want to use "/en/" as your external pages prefix, and that is totally fine and completely up to you. The reason I put my pages in a sub-folder is so I could use the case statement to display the specific Controller Page. (which is in the En.php file under the Router/Prefix directory) Otherwise you have to create a route for each external page and a function for each route handler. (I think, lol. Haven't played with that part yet. :))

    You will notice that the new NAV tab are setup for my sites. (NFL fan site) You can change any/all of the tabs in the Navigation.php under the Listerners folder.

    Under the ControllerPublic folder, you will notice that EACH pages has its own PHP file. I copied some code from XenPorta to create a few of the sidebar pieces in each of the pages. Eventually, I am going to add a function to build right rails, but for now each pages has its own right rail creation code. Of course, you can ADD or remove these(ControllerPublic Pages) as you see fit.

    Inside each ControllerPublic file you will see that it displays a template from this line:
    return $this->responseView('ExternalPages_ViewPublic_Advertise', 'EP_Advertise', $viewParams);

    The above line was from the Advertise.php file under the ControllerPublic folder. I am hoping that you guys can pick up on the naming scheme that I am using and can figure out how to modify these files to match your preferences and external pages.

    Each ControllerPublic file can have its OWN set of information you assign into the template through the $viewParams array. Most of the pages I have provided only assign onlineUsers and boardTotals. Of course, you can assign as many more variables as you need.

    Now for the templates you will need to create. Lets look at the EP_Advertise template:

    <xen:h1>Welcome to Seahawks Huddle Advertising</xen:h1>
    <xen:title>Advertise on Seahawks Huddle</xen:title>
    <xen:description>Enter a META description/page description here.</xen:description>
        <xen:breadcrumb href="{xen:link full:en/advertise/}">Advertise With Us</xen:breadcrumb>
        <xen:include template="sidebar_online_users" />
        <xen:include template="forum_stats" />
    The one thing you should note in the above template at the reason why I posted it is because it is NOT in the Navigation.php file. So I have to add the breadcrumb through the template file. All the external pages that you put in the Navigation.php will NOT need the breadcrumb code in the template.

    I added a screen shot of what my SCHEDULE page looks like. You can see that the custom NAVBAR option lights up. Each external pages uses the BASE Right Rail from the PAGE_CONTAINER template. You can add elements to each template between the <xen:sidebar></xen:sidebar> tags.

    Holy crap that was a lot longer than I thought it was going to be. I will do my best to answer questions. :) The name of the game here is to just play. That is pretty much what I did and I came up with this. :) I will have my site launching in about 48 hours so you can see a live demo or get this going on your own. Good luck and I love this damn software!

    Attached Files:

  2. Digital Doctor

    Digital Doctor Well-Known Member

    What would an external page look like ?
    Can you get it to appear in a Custom Tab ?
    Thanks for sharing. Cool stuff.
  3. robdog

    robdog Well-Known Member

    Each external page can look different. The template I post above will have breadcrumbs and a side bar.

    And yes, your external pages CAN have custom NAV tabs. I attached a file that ADDS 3, but they are for my site (Tickets, Schedule, Draft). You can change them to whatever you want. (add some or remove some)
  4. Ray

    Ray Active Member

  5. Digital Doctor

    Digital Doctor Well-Known Member

    That page looks great !
    So good, I'm giving it my Xenforo T-Shirt award ! :)


    Addendum: I don't think the Seahawks are going to be effective at selling women's shampoo, but hey, I'm not in marketing !
    Earl likes this.
  6. robdog

    robdog Well-Known Member

  7. robdog

    robdog Well-Known Member

    haha... after I posted it I thought of refreshing the page and getting a new ad, but now I am just going to let it ride. :) (got to love Google)
  8. Miko

    Miko Well-Known Member

    thank you robdog, you made my day :)
  9. masterchief

    masterchief Well-Known Member

    you accomplished this via the navigation.php file?
  10. robdog

    robdog Well-Known Member

    Navigation.php is specifically for adding custom navigation tabs. This is optional and you can remove it all together and remove the event listener that is attached to it as well.

    Each pages has its own controller PHP file which is in the ControllerPublic folder. Inside each of those PHP files you will see it assigned an array values to be used by a template. Those templates can be customized to look and feel however you want.

    I will have my XenForo site up tonight around 11:00pm PST, which will have a number of external pages in use.
  11. masterchief

    masterchief Well-Known Member

    I installed it on my system... works great. I found the three extra tabs on the navbar. To make sure I understand, I create a template for each of those extra tabs, and then the page will show when I select the tabs..

    excellent addon, brings me closer to trying to create my own. peace
  12. robdog

    robdog Well-Known Member

    Yes, lets say you didn't change any of the PHP files and you click on the Schedule Tab. It will look for the "EP_Schedule" template.
  13. masterchief

    masterchief Well-Known Member

    got it... THANK YOU! additionally, how would I turn off this addon from the ACP? extra tabs are only thing affected when clearing checkbox in the Addon listing from the ACP.

    how to do submenus??
  14. robdog

    robdog Well-Known Member

    Unchecking the addon will only remove the custom tabs. If you disable the custom route, you will disable the external pages.

    I have not played with sub-pages yet, but I have a second website that I am going to be working with that will require sub-options.

    I will update this thread when I add sub-options.
    Miko likes this.
  15. masterchief

    masterchief Well-Known Member

    external pages need tobe driven from navigation.php then ... external tab data. think about embedding subtabs within external paves in addition to option of having submenus on the navbar .. peace
  16. robdog

    robdog Well-Known Member

    You can change the files to do that. However, I will leave my Navigation.php to only control the navigation. Because you might have some external pages that do not have navigation tabs. (terms, privacy, advertising, etc...)
  17. masterchief

    masterchief Well-Known Member

    light just came on upstairs... you have given me more ideas... I like your addon.
  18. erich37

    erich37 Well-Known Member

    would be cool to have this as per default in XF............
    Digital Doctor likes this.
  19. Digital Doctor

    Digital Doctor Well-Known Member

    Yes, probably will .... "in time".

    Make sure these pages are editable outside the AdminCP. Which is another major limitation of Xenforo's native "Pages".
    erich37 likes this.
  20. robdog

    robdog Well-Known Member

    I am hoping the guys from vbAdvanced keep true to their promise on xfAdvanced. :) One can dream right!

    Point being, this will unlikely be something default in the system.

Share This Page