XF 2.1 Is it possible to generate/re-create the public navigation externally?

asprin

Active member
Hi experts,

The goal is to get the HTML of the following menu
1578906506562.webp

so that I can use the same in an external application (hosted on the same server but outside Xenforo)

I've tried using the following so far:
PHP:
$navRepo      = \XF::app()->repository( 'XF:Navigation' );
$navCacheData = $navRepo->createNavigationTree();
$data = $navCacheData->getDescendants();

print_r($data);

But this doesn't seem to correspond to the above navigation that is visible to a logged-in user. Any suggestions?
 
What you have is the raw data. It needs to be rendered first. While parts of the navigation are available in the PAGE_CONTAINER template to be used externally via macro rendering, not all of it is, so you'll have to recreate some parts yourself.
 
What you have is the raw data. It needs to be rendered first. While parts of the navigation are available in the PAGE_CONTAINER template to be used externally via macro rendering, not all of it is, so you'll have to recreate some parts yourself.
Is there an example somewhere that I can refer to? Very new to the terms here (like macro rendering), so I'm not entirely sure I'm following it correctly.
 
This maybe the easiest way to get you what you need:

 
This maybe the easiest way to get you what you need:

Easiest - probably. But will cost $$. I feel it's better if I learn it myself :)
 
Any chance there is an example sample/code of macro rendering that Lucas was referring to for me to study and replicate?
 
Last edited:
I asked the same thing for a long time around here (months), until I finally paid someone to come up with a great solution.


Yes, it isn't free but if you've wasted more than a couple hours on it already, you could've already paid for it. Time is money.

Just trying to save you some time and headaches, because it isn't a couple simple lines of code someone can share - that will never work. It's much more in-depth and requires quite a bit of XenForo knowledge to make something that integrates seamlessly.

You can always come up with your own custom solution once you have something up and running to compare to.

I don't make a dime off of this suggestion. I was just in the same place you were and I promise this is the only working solution currently available for what you want to do.
 
I asked the same thing for a long time around here (months), until I finally paid someone to come up with a great solution.


Yes, it isn't free but if you've wasted more than a couple hours on it already, you could've already paid for it. Time is money.

Just trying to save you some time and headaches, because it isn't a couple simple lines of code someone can share - that will never work. It's much more in-depth and requires quite a bit of XenForo knowledge to make something that integrates seamlessly.

You can always come up with your own custom solution once you have something up and running to compare to.

I don't make a dime off of this suggestion. I was just in the same place you were and I promise this is the only working solution currently available for what you want to do.
I know you mean well and I appreciate it. It's just that I gain immense pleasure when solving it on my own. Having said that, given that there hasn't been further discussions on this, I've gone ahead and contacted him. Let's see how it goes from there.
 
Honestly, there is no easy answer. I have coded additional "wrappers" that I use for all of my external pages. And as of right now, my project doesn't even use a forum. I am using XenForo for the platform to build out my product. Here are a couple of examples:

Screen Shot 2020-01-22 at 8.12.24 AM.webp

Screen Shot 2020-01-22 at 8.13.13 AM.webp

Something to note, this has been a lot of custom work, but none of the core XenForo files have been changed. I can try and answer as many questions as possible, but time is limited. However, it is possible if you really wanted to get your hands dirty or hire a coder to make this work for you.
 
That's quite encouraging. And yes, I don't mind digging in and try something out myself. Like I said in the opening post, I'm able to fetch the nodes information but it isn't matching with what is shown to the user. For example, in the screenshot I see 3 parent navigation links:
  1. Forums
  2. What's New
  3. Members
However, in the raw data (\XF::app()->repository( 'XF:Navigation' );), I see the following parent links:
  1. _default
  2. home
  3. forums
  4. whatsNew
  5. members
I'm able to construct child level data as well but what I'm not able to figure out is the basis on which _default and home links are excluded when the navigation links are being rendered.

As a last resort, I'm also willing to take the route of generating the HTML (same tags and class names as used by Xenforo in their navigation markup) using the above raw data. Then it would simply be a question of referencing the forum's stylesheet in my external app.
 
@asprin You mind me asking what the external pages are? Is this for another framework that you are trying to put XenForo navigation on? Or are you making custom controller/actions within XenForo?
 
Is this for another framework that you are trying to put XenForo navigation on?
Yep. It's an application built using Codeigniter 3. I'm passing the session data to it and that let's a user perform certain actions on the external app (which I then use to create automated threads/posts in Xenforo as and when required). It's sort of a fantasy league type of application.
 
Top Bottom