XF 2.1 Node page and template syntax: Can I retrieve a single post?

Wildcat Media

Well-known member
Since we don't have a WYSIWYG text editor, I am trying to come up with a way to display a nicely formatted page that is easy for myself and the staff to maintain.

My idea is to create a new node, not listed in the node tree, yet still publicly viewable (view node permission is "yes"). Within that, we create a thread where the first post in the thread has the documentation we want for a specific page.

When creating a page node, we can use template syntax. 💡 That gives me an idea. Why can't I use template syntax to return the fully formatted body of the first post in one thread to display as the contents of the page? I don't need thread title, reactions, etc., nothing at all except the post body. I've poked at it by borrowing some code from a couple of the templates (I'm thinking message_macros probably has something I can modify and use), but I didn't get anywhere. Essentially, my solution would include a variable where I could enter the post number (and thread number if needed), and display only that post.

Is this even possible? Has anyone ever tried this? My coding days are past, so trying to write something from the ground up likely won't happen. But even if I can get a hint as to what parts of existing templates I might need, that might help out a little.
 
You'll need a page callback to retrieve the post in the first instance, but rendering its message is just a thing of calling the bb_code() function in your template.
 
That's way beyond my abilities, so it's probably more difficult than I thought.

We'll have to figure out something else...
 
I sort of got something working here, but it's clumsy--another member here helped me get it working with an array that maps the page node to the thread ID.

Trying to make it work from an <xf:callback ... in the page node template has been impossible so far. My idea was to use this to enter a thread number as one of the params, and have that retrieve the first post and display it in the page. I can't get any output, though, so I'm going to revisit this after we launch the upgrade within the week. Got stalled here: https://xenforo.com/community/threads/display-a-thread-post-in-xenforos-page.164457/post-1417577 .
 
Nailed it! See the thread I linked above. I'll probably drop this in Resources somewhere, probably as a how-to as I won't be able to support it as an add-on (although that's how I have it set up in our forum).
 
BTW, this same method can be used to create easily editable help pages as well. Rather than create a page node for each document, you would add a new help page and use the same format. I will need to clean up and paste the code in here once I am not under deadline with this upgrade.

Question for @Chris D -- what is the significance of attaching a help page to an add-on? If I create an add-on, would the code for these new help pages then be installed if I export the add-on and then install it on another forum? Or if I don't want that behavior, would I simply not attach them to an add-on, or attach it to the "XenForo" add-on instead?
 
Yes. Attaching anything to an add-on means it now belongs to that add-on and will be exported with it.

Never attach anything to an add-on that isn’t yours. Including XF. It will disappear during an add-on upgrade or XF upgrade if you attach it to XF.

If you have no need for it to be part of an add-on just leave that field blank.
 
Top Bottom