XF 2.1 $node, $forum, $thread, $post

Robert9

Well-known member
In my thread i have $forum and $thread
In my post i have $post and $thread

How can i let the post_macro know something about a value in $forum?
Just pass it with args? (Tried it without success)
 
Answer:

In my case the field is test with 0/1

In thread_view i can extend the call of post_macros with
arg-test="{$forum.field} ? 1 : 0"

in post_macros
<xf:macro name="post" arg-post="!" arg-thread="!" arg-test="!">

and use
{test}

The rest is to add two template-mods to add

arg-test="{$forum.field} ? 1 : 0" to thread_view

and

arg-test="!" to post_macros
 
Last edited:
Relations?

For this example?

The only thing to do here, is to make "$forum.anyfield" accessable in post_macros.
 
.offtop: every day I observe from you several questions related to the development. And judging by them, you did not even really familiarize yourself with the documentation. Before learning to program, you need to learn how to look for answers to questions. Most questions are answered on the Internet. Just before asking another question, first try to find the answer to it yourself: on the Internet, in the engine, in additions. You will not learn anything if others do everything for you.

"You cannot help people permanently by doing for them, what they could and should do for themselves." (c) A. Lincoln
 
And how do you think a forum is filled with answers?
By people with questions and people answering them.

(c) Robert9 & Aristoteles

You can be shure that i use the search very often, but there is normally no answer for me.
But in this thread we have now an answer, because i have asked before.
 
Last edited:
If you have the Post entity, you can retrieve the Thread entity via relation. From the thread entity you can go to the node entity.
 
Thank you Lukas.
But all information is still there, there is no need to retrieve anything. (When you see a thread you have $forum, $thread and all $posts)

dump($forum) in thread_view shows $forum

thread_view calls post_macros with args ($thread and $post)

Everything i have to do is to extend the call with the arg $forum in thread_view
and to fetch and use the data in post_macros

The answer for #1 is in #2. :)

I guess to understand what you mean with relations; i have used the relations yesterday the first time in another add-on,
where i had to fetch RMItem to rows in my own table. It had big problems till i have changed the name of my own_table.primary to resource_id.
So i guess, that the name needs to be the same every time, while i was not able to say LEFT JOIN ON (own.primary=rm.resource_id) it is easy to use with (own.resource_id=rm.resource_id).

After understanding that relation_name.field could be used for the ->where everything was easy.
 
Last edited:
This arg-test="!" makes problems with other functions, when the value is not there. (New post for example).

arg-test="!" and arg-test="{$forum.field} ? 1 : 0" fix it.
 
Thought i could start the next add-on, but there is a problem with my way, while the quickbox save doesnt go the same way like showing a thread.
$forum is missing in the first way. So somehow i need a global or something to hold the value.
 
Back
Top Bottom