XF 2.2 Modify template for specific nodes

Lucianin

Member
Hello.
I have a second doubt of the day (sorry).

Context: I have several "new threads" widget that are not shown to guests, because I want them to see the title, but not the content. So xenforo, despite having the option to only hide the content enabled, for some reason it does not show it in the widgets.

In front of that, it is that I found the option to hide the content superior to x words.

The problem: I have to modify the template and it modifies all themes, and I only want to hide it on certain nodes. So I don't know how to apply it for given number of nodes.

Template is
Code:
post_macros

The original lines are:

HTML:
<article class="message-body js-selectToQuote">
            <xf:if is="$displayAds">
                <xf:ad position="post_above_content" arg-post="{$post}" />
            </xf:if>
            <xf:if is="$snippet">
                {{ bb_code_snippet($post.message, 'post', $post, $snippet) }}
            <xf:else />
                {{ bb_code($post.message, 'post', $post) }}
            </xf:if>
            <div class="js-selectToQuoteEnd">&nbsp;</div>
            <xf:if is="$displayAds">
                <xf:ad position="post_below_content" arg-post="{$post}" />
            </xf:if>
        </article>

And i need to change to:

HTML:
<article class="message-body js-selectToQuote">
            <xf:if is="$displayAds">
                                <xf:ad position="post_above_content" arg-post="{$post}" />
                </xf:if>
                                <xf:if is="!$xf.visitor.user_id">
                                    <xf:set var="$snippetPost" value="{{ snippet($post.message, 10) }}" />
                                    {{  bb_code($snippetPost, 'post', $post)  }}
                                    <div class="blockMessage blockMessage--important blockMessage--iconic">
                                       Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
                                    </div>
                                <xf:else/>
                                    {{ bb_code($post.message, 'post', $post) }}
                                </xf:if>
                                <div class="js-selectToQuoteEnd">&nbsp;</div>
                <xf:if is="$displayAds">
                                <xf:ad position="post_below_content" arg-post="{$post}" />
                    </xf:if>
                            </article>

The nodes where I want to hide the messages are for example /xxxxx.1 or /xxyyy.24

Can you help me?

Thank you very much and sorry friends for bothering you so often.
 
Solution
ok, change this
<xf:if is="in_array($containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
to this in the code
<xf:if is="in_array($xf.reply.containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
and try again.
If i understand well what you want you can probably test this
HTML:
<xf:if is="in_array($containerKey, ['node-1', 'node-2', 'node-3'])">
    your custom code
<xf:else/>
    the original code
</xf:if>
 
If i understand well what you want you can probably test this
HTML:
<xf:if is="in_array($containerKey, ['node-1', 'node-2', 'node-3'])">
    your custom code
<xf:else/>
    the original code
</xf:if>

This is the result and it didn't work for me.:

HTML:
        <article class="message-body js-selectToQuote">
            <xf:if is="$displayAds">
                <xf:ad position="post_above_content" arg-post="{$post}" />
            </xf:if>
            <xf:if is="$snippet">
                {{ bb_code_snippet($post.message, 'post', $post, $snippet) }}
            <xf:else />
                {{ bb_code($post.message, 'post', $post) }}
            </xf:if>
            <div class="js-selectToQuoteEnd">&nbsp;</div>
            <xf:if is="$displayAds">
                <xf:ad position="post_below_content" arg-post="{$post}" />
            </xf:if>
        </article>
        
        <xf:if is="in_array($containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
    <article class="message-body js-selectToQuote">
            <xf:if is="$displayAds">
                           <xf:ad position="post_above_content" arg-post="{$post}" />
            </xf:if>
                            <xf:if is="!$xf.visitor.user_id">
                                <xf:set var="$snippetPost" value="{{ snippet($post.message, 10) }}" />
                                {{  bb_code($snippetPost, 'post', $post)  }}
                                <div class="blockMessage blockMessage--important blockMessage--iconic">
                                   Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
                                </div>
                            <xf:else/>
                                {{ bb_code($post.message, 'post', $post) }}
                            </xf:if>
                            <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
                            <xf:ad position="post_below_content" arg-post="{$post}" />
            </xf:if>
                        </article>
<xf:else/>
            <article class="message-body js-selectToQuote">
            <xf:if is="$displayAds">
                <xf:ad position="post_above_content" arg-post="{$post}" />
            </xf:if>
            <xf:if is="$snippet">
                {{ bb_code_snippet($post.message, 'post', $post, $snippet) }}
            <xf:else />
                {{ bb_code($post.message, 'post', $post) }}
            </xf:if>
            <div class="js-selectToQuoteEnd">&nbsp;</div>
            <xf:if is="$displayAds">
                <xf:ad position="post_below_content" arg-post="{$post}" />
            </xf:if>
        </article>
</xf:if>
 
Remove the first block code, it is redundant and it's avoid the conditional code to run
HTML:
<xf:if is="in_array($containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">

    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="!$xf.visitor.user_id">
        <xf:set var="$snippetPost" value="{{ snippet($post.message, 10) }}" />
            {{  bb_code($snippetPost, 'post', $post)  }}
        <div class="blockMessage blockMessage--important blockMessage--iconic">
            Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
        </div>
   <xf:else/>
       {{ bb_code($post.message, 'post', $post) }}
   </xf:if>
   <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
        </xf:if>
    </article>

<xf:else/>

    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="$snippet">
        {{ bb_code_snippet($post.message, 'post', $post, $snippet) }}
    <xf:else />
        {{ bb_code($post.message, 'post', $post) }}
    </xf:if>
    <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
       </xf:if>
    </article>

</xf:if>
 
Remove the first block code, it is redundant and it's avoid the conditional code to run
HTML:
<xf:if is="in_array($containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">

    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="!$xf.visitor.user_id">
        <xf:set var="$snippetPost" value="{{ snippet($post.message, 10) }}" />
            {{  bb_code($snippetPost, 'post', $post)  }}
        <div class="blockMessage blockMessage--important blockMessage--iconic">
            Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
        </div>
   <xf:else/>
       {{ bb_code($post.message, 'post', $post) }}
   </xf:if>
   <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
        </xf:if>
    </article>

<xf:else/>

    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="$snippet">
        {{ bb_code_snippet($post.message, 'post', $post, $snippet) }}
    <xf:else />
        {{ bb_code($post.message, 'post', $post) }}
    </xf:if>
    <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
       </xf:if>
    </article>

</xf:if>

didn't work :(:(:(:(
 
Is this part of code, alone, works ?
If you replace the original code by this one you get what you want ? (except it is not targetting nodes)

HTML:
    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="!$xf.visitor.user_id">
        <xf:set var="$snippetPost" value="{{ snippet($post.message, 10) }}" />
            {{  bb_code($snippetPost, 'post', $post)  }}
        <div class="blockMessage blockMessage--important blockMessage--iconic">
            Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
        </div>
   <xf:else/>
       {{ bb_code($post.message, 'post', $post) }}
   </xf:if>
   <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
        </xf:if>
    </article>
 
Is this part of code, alone, works ?
If you replace the original code by this one you get what you want ? (except it is not targetting nodes)

HTML:
    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="!$xf.visitor.user_id">
        <xf:set var="$snippetPost" value="{{ snippet($post.message, 10) }}" />
            {{  bb_code($snippetPost, 'post', $post)  }}
        <div class="blockMessage blockMessage--important blockMessage--iconic">
            Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
        </div>
   <xf:else/>
       {{ bb_code($post.message, 'post', $post) }}
   </xf:if>
   <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
        </xf:if>
    </article>

With that code it looks like this:

modificado.webp

And with the original code it looks normal:

original.webp


In this thread https://odum.cl/tema/cupon-antiguo-usuario-tenpo.40925/

The problem is that the code hides ALL topics, and I only need to hide topics from certain nodes.
 
ok, change this
<xf:if is="in_array($containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
to this in the code
<xf:if is="in_array($xf.reply.containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
and try again.
 
Solution
ok, change this
<xf:if is="in_array($containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
to this in the code
<xf:if is="in_array($xf.reply.containerKey, ['node-243', 'node-376', 'node-250', 'node-369', 'node-379', 'node-247', 'node-323', 'node-325'])">
and try again.

Wow!!! Thank you!!!

Thank you very much, that is the solution.

I searched for the information for many months, so I will leave it explained for whoever needs it.

1) node-1, node-2 or node-3, the number is the number of the node to which you want to hide the message

2) in the line <xf:set var="$snippetPost" value="{{ snippet($post.message, 300) }}" />

look at ($post.message, 300) and leave 300 or less in the number of characters you want to show, after that it will hide

Template post_macros:

HTML:
<xf:if is="in_array($xf.reply.containerKey, ['node-1', 'node-2', 'node-3'])">

    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="!$xf.visitor.user_id">
        <xf:set var="$snippetPost" value="{{ snippet($post.message, 1) }}" />
            {{  bb_code($snippetPost, 'post', $post)  }}
        <div class="blockMessage blockMessage--important blockMessage--iconic">
            Para ver el contenido oculto, por favor, <a href="{{ link('login') }}" data-xf-click="overlay">{{ phrase('log_in_or_register_now') }}</a>
        </div>
   <xf:else/>
       {{ bb_code($post.message, 'post', $post) }}
   </xf:if>
   <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
        </xf:if>
    </article>

<xf:else/>

    <article class="message-body js-selectToQuote">
    <xf:if is="$displayAds">
        <xf:ad position="post_above_content" arg-post="{$post}" />
    </xf:if>
    <xf:if is="$snippet">
        {{ bb_code_snippet($post.message, 'post', $post, $snippet) }}
    <xf:else />
        {{ bb_code($post.message, 'post', $post) }}
    </xf:if>
    <div class="js-selectToQuoteEnd">&nbsp;</div>
        <xf:if is="$displayAds">
            <xf:ad position="post_below_content" arg-post="{$post}" />
       </xf:if>
    </article>

</xf:if>
 
Top Bottom